javascript - how to include a prototype in typescript -


i learning angular 2 , have written ts definition truncate method want use in 1 of services.

truncate.ts

interface string {     truncate(max: number, decorator: string): string; }  string.prototype.truncate = function(max, decorator){    decorator = decorator || '...';    return (this.length > max ? this.substring(0,max)+decorator : this); }; 

how import typescript module or @ least make available use globally.

how import typescript module or @ least make available use globally.

move file stringextenions.ts:

interface string {     truncate(max: number, decorator: string): string; }   string.prototype.truncate = function(max, decorator){    decorator = decorator || '...';    return (this.length > max ? this.substring(0,max)+decorator : this); }; 

and import file like:

import "./stringextensions" 

more

https://basarat.gitbooks.io/typescript/content/docs/types/lib.d.ts.html


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -