View package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "webpack-sample", | |
"version": "0.0.1", | |
"description": "Webpack sample - first try", | |
"main": "", | |
"scripts": { | |
"start": "webpack" | |
}, | |
"repository": { | |
"type": "git", |
View webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
entry: __dirname + "/app/main.js", | |
output: { | |
path: __dirname + "/public", | |
filename: "app.js" | |
}, | |
devServer: { | |
contentBase: "./public", | |
historyApiFallback: true, | |
inline: true, |
View package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "webpack-sample", | |
"version": "0.0.1", | |
"description": "Webpack sample - first try", | |
"main": "", | |
"scripts": { | |
"start": "webpack-dev-server --progress" | |
}, | |
"repository": { | |
"type": "git", |
View decorators-composition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test { | |
public name: string; | |
constructor(name: string) { | |
this.name = name; | |
} | |
@a() | |
@b() | |
@c() |
View decorators.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function log(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) { | |
console.log('target:', target); | |
console.log('propertyKey:', propertyKey); | |
console.log('descriptor:', descriptor); | |
// save a reference to the original method | |
let originalMethod = descriptor.value; | |
descriptor.value = function (...args: any[]) { | |
// pre |
View typescript-tuple-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let tupleType: [string, number]; | |
tupleType = ['hey', 13]; | |
// tupleType = [5, 'hey']; // Error - '[number, string]' is not assignable to '[string, number]' | |
// tupleType = ['hey', 'tuple']; // Error - '[string, string]' is not assignable to '[string, number]' | |
tupleType[3] = 54; // this works well because union type string | number is used for indices outside of known ones | |
tupleType[4] = 'test'; // works well because it can be string or number, union type | |
// tupleType[5] = true; // Error - Type 'true' is not assignable to type 'string | number' |
View typescript-type-guards.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student { | |
study() { | |
} | |
} | |
class Professor { | |
teach() { | |
} | |
} | |
function getPerson(n: number): Student | Professor { | |
if (n === 1) { |
View typescript-union-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function print(text: string | string[]): string { | |
if (typeof text === 'string') { | |
return text; | |
} | |
// compiler now knows that you can use join | |
// and that variable type is definitely string[] | |
return text.join(' '); | |
} |
View typescript-union-types-interfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IStudent { | |
id: string; | |
age: number; | |
} | |
interface IWorker { | |
companyId: string; | |
} | |
type IUnionType = IStudent | IWorker; |
View typescript-intersection-types-overlap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface X { | |
c: string; | |
d: string; | |
} | |
interface Y { | |
c: number; | |
e: string | |
} |
OlderNewer