Skip to content

Instantly share code, notes, and snippets.

@jawache
Last active April 5, 2017 02:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jawache/f4e54b8540ed2674d34629047959a6ab to your computer and use it in GitHub Desktop.
Save jawache/f4e54b8540ed2674d34629047959a6ab to your computer and use it in GitHub Desktop.
typescriptcrashcourse
let obj = {
name: "Asim",
sayLater: function() {
// this...
setTimeout(() => console.log(`${this.name}`), 1000)
}
};
obj.sayLater();
'use strict';
const foo = Object.freeze({});
foo.prop = 1;
console.log(foo.prop);
// const arr = ['a', 'b'];
// const [x, y] = arr;
// console.log(x);
// console.log(y);
function func({x=1}) {
console.log(x);
}
func({});
// const obj = {first: 'Asim', last: 'Hussain', age: 39 };
//
// function getObj() {
// return obj;
// }
//
// const {first, last} = getObj();
//
// console.log(first);
// console.log(last);
'use strict';
let funcs = [];
for (let i = 0; i < 10; i += 1) {
funcs.push(function () {
console.log(i);
})
}
funcs.forEach(function (func) {
func()
});
// var a = "global";
// function hello() {
// var a = "function";
// for (var i = 0; i < 10; i++) {
// let a = "block";
// }
// console.log(a);
// }
// hello();
let name = "Asim";
let single = `hello
world
my
name
is
${name}`;
console.log(single);
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
name() {
return `${this.firstName} ${this.lastName}`;
}
whoAreYou() {
return `Hi i'm ${this.name()}`;
}
}
class Student extends Person {
constructor(firstName, lastName, course) {
super(firstName, lastName);
this.course = course;
}
whoAreYou() {
return `${super.whoAreYou()} and i'm studying ${this.course}`;
}
}
let asim = new Student("Asim", "Hussain", "typescript");
console.log(asim.whoAreYou());
class Person {
constructor(private firstName, private lastName) {
}
public name() {
return `${this.firstName} ${this.lastName}`;
}
protected whoAreYou() {
return `Hi i'm ${this.name()}`;
}
}
class Student extends Person {
course;
constructor(firstName, lastName, course) {
super(firstName, lastName);
this.course = course;
}
whoAreYou() {
return `${super.whoAreYou()} and i'm studying ${this.course}`;
}
}
let asim = new Student("Asim", "Hussain", "typescript");
console.log(asim.whoAreYou());
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
function Student(config) {
return function (target) {
Object.defineProperty(target.prototype, 'course', { value: function () { return config.course; } });
};
}
var Person = (function () {
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.name = function () {
return this.firstName + " " + this.lastName;
};
Person.prototype.whoAreYou = function () {
return "Hi i'm " + this.name();
};
Person = __decorate([
Student({
course: "angular3"
})
], Person);
return Person;
}());
var asim = new Person("Asim", "Hussain");
console.log(asim.course());
function Student(config) {
return function (target) {
Object.defineProperty(target.prototype, 'course', {value: () => config.course})
}
}
@Student({
course: "angular3"
})
class Person {
constructor(private firstName, private lastName) {
}
public name() {
return `${this.firstName} ${this.lastName}`;
}
protected whoAreYou() {
return `Hi i'm ${this.name()}`;
}
}
let asim = new Person("Asim", "Hussain");
console.log(asim.course());
"use strict";
function square(x) {
return Math.pow(x, 2);
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = square;
function cow() {
console.log("Mooooo!!!");
}
exports.cow = cow;
export default function square(x) {
return Math.pow(x,2)
}
export function cow() {
console.log("Mooooo!!!")
}
"use strict";
var module1_1 = require('./module1');
console.log(module1_1.default(4));
module1_1.cow();
import square, {cow} from './module1';
console.log(square(4));
cow();
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"sourceMap": false
},
"exclude": [
"node_modules"
]
}
var Direction;
(function (Direction) {
Direction[Direction["Up"] = 0] = "Up";
Direction[Direction["Down"] = 1] = "Down";
Direction[Direction["Left"] = 2] = "Left";
Direction[Direction["Right"] = 3] = "Right";
})(Direction || (Direction = {}));
var a = 1;
a = "2";
enum Direction {
Up,
Down,
Left,
Right
}
let a = 1;
a = "2";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment