How can I extends a built-in Constructor?

Topics: General
Feb 6, 2014 at 12:23 PM
How can I extends a built-in Constructor?

I want to create es6-shim.d.ts. ( https://github.com/es-shims/es6-shim

e.g.
// lib.d.ts
declare var String: {
    new (value?: any): String;
    (value?: any): string;
    prototype: String;
    fromCharCode(...codes: number[]): string;
}

// es6-shim.d.ts
// http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts
declare var String : {
  raw(callSite: any, ...substitutions: any[]): any; 
}
but this declaration source file is invalid.
variable can't be merging type declaration.
Is not good means something?

My proposal: use the interface more! it is able to lib.d.ts more expandable.
// lib.d.ts
interface IStringStatic {
    new (value?: any): String;
    (value?: any): string;
    prototype: String;
    fromCharCode(...codes: number[]): string;
}
declare var String: IStringStatic;

// es6-shim.d.ts
interface IStringStatic {
  raw(callSite: any, ...substitutions: any[]): any;
}
other examples.
https://github.com/borisyankov/DefinitelyTyped/pull/1618
Developer
Feb 6, 2014 at 9:05 PM
Yeah this has been an issue for awhile and still is. We've talked about a few potential fixes but haven't landed on one we like yet. See these issues (and upvote as you please) for additional discussion points:

https://typescript.codeplex.com/workitem/482
https://typescript.codeplex.com/workitem/1085
Feb 13, 2014 at 2:50 PM
thank you so much!
I'm voted!