angular - Extension for window.Node in Typescript -


i'm trying add new method window.node

interface node {     mymethod(selector: any): }  node.prototype.mymethod = (selector) => {    //some code } 

and use in code, method not defined. can understand after running "ionic serve" code not included in build version.

my tsconfig.json file

"compileroptions": {     "allowsyntheticdefaultimports": true,     "declaration": false,     "emitdecoratormetadata": true,     "experimentaldecorators": true,     "lib": [         "dom",         "es2015"     ],     "module": "es2015",     "moduleresolution": "node",     "sourcemap": true,     "target": "es5" }, "files": [     "src/app/customextensions/extensions.ts" //file new method ], "include": [     "src/**/*.ts" ], "exclude": [     "node_modules" ], "compileonsave": false, "atom": {     "rewritetsconfig": false } 

i've tried add

/// <reference path="customextensions/extensions.ts" /> 

to app.component.ts still doesn't work.

update: extension methods in typescript (system) - paul's solution solves issue.

typescript not generate code interfaces. go typescript playground , check. [https://www.typescriptlang.org/play/][1]

in extensions.ts do:

export interface node {    mymethod(selector: any): } export const mynode : node = {   mymethod(selector: any): {      // put function body here   } } 

and in code can import mynode , call method on it

import {mynode} 'app/customextensions/extensions';  mynode.mymethod(); 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -