Last active
April 29, 2019 09:22
-
-
Save w8r/b854317360e129f6582fc461162ca794 to your computer and use it in GitHub Desktop.
Namespaces vs. classes
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
node_modules | |
dist |
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
declare class API { | |
private _instance; | |
constructor(instance: Ogma); | |
method1(a: number): string; | |
method2(a: string): number; | |
method3(): Ogma; | |
} | |
export default class Ogma { | |
api: API; | |
constructor(); | |
} | |
export {}; |
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
"use strict"; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
var API = /** @class */ (function () { | |
function API(instance) { | |
this._instance = instance; | |
} | |
API.prototype.method1 = function (a) { | |
return 'a'; | |
}; | |
API.prototype.method2 = function (a) { | |
return 1; | |
}; | |
API.prototype.method3 = function () { | |
return this._instance; | |
}; | |
return API; | |
}()); | |
var Ogma = /** @class */ (function () { | |
function Ogma() { | |
this.api = new API(this); | |
} | |
return Ogma; | |
}()); | |
exports.default = Ogma; |
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 API { | |
private _instance:Ogma; | |
constructor(instance:Ogma) { | |
this._instance = instance; | |
} | |
method1(a:number):string { | |
return 'a'; | |
} | |
method2(a:string):number { | |
return 1; | |
} | |
method3():Ogma { | |
return this._instance; | |
} | |
} | |
export default class Ogma { | |
public api:API; | |
constructor () { | |
this.api = new API(this); | |
} | |
} |
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 API { | |
method1(a: number): string; | |
method2(a: string): number; | |
method3(): Ogma; | |
} | |
export default class Ogma { | |
api: API; | |
constructor(); | |
} | |
export {}; |
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
"use strict"; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
function api(instance) { | |
return { | |
method1: function (a) { | |
return 'a'; | |
}, | |
method2: function (a) { | |
return 1; | |
}, | |
method3: function () { | |
return instance; | |
} | |
}; | |
} | |
var Ogma = /** @class */ (function () { | |
function Ogma() { | |
this.api = api(this); | |
} | |
return Ogma; | |
}()); | |
exports.default = Ogma; |
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 API { | |
method1(a:number):string; | |
method2(a:string):number; | |
method3():Ogma | |
} | |
function api (instance:Ogma) { | |
return { | |
method1(a:number):string { | |
return 'a'; | |
}, | |
method2(a:string):number { | |
return 1; | |
}, | |
method3():Ogma { | |
return instance; | |
} | |
}; | |
} | |
export default class Ogma { | |
public api:API; | |
constructor () { | |
this.api = api(this); | |
} | |
} |
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": "temp", | |
"version": "1.0.0", | |
"lockfileVersion": 1, | |
"requires": true, | |
"dependencies": { | |
"typescript": { | |
"version": "3.4.5", | |
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", | |
"integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", | |
"dev": true | |
} | |
} | |
} |
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": "temp", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"build": "tsc -d" | |
}, | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"typescript": "^3.4.5" | |
}, | |
"dependencies": {} | |
} |
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
Show hidden characters
{ | |
"compileOnSave": true, | |
"compilerOptions": { | |
"target": "es5", | |
"lib": ["es2015", "es2017", "dom"], | |
"sourceMap": false | |
}, | |
"include": [ | |
"./namespaces.ts", "./classes.ts" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment