ecmascript 6 - TypeScript | Array.from | error TS2339: Property 'from' does not exist on type 'ArrayConstructor' -
i googling, cannot find information , how should add project allow me using es6 methods array.from
__ edit: removed prototype word
you can extend existing types so:
interface array { from(arraylike: any, mapfn?, thisarg?): array<any>; } the problem here add function array instances , not static function require.
can done so:
interface arrayconstructor { from(arraylike: any, mapfn?, thisarg?): array<any>; } then should able use array.from.
try out on playground.
edit
if need polyfill implementation (because environment in intend run doesn't have it), how:
interface arrayconstructor { from(arraylike: any, mapfn?, thisarg?): array<any>; } array.from = function(arraylike: any, mapfn?, thisarg?): array<any> { // place code mdn here } 2nd edit
based on comment, i'm adding typed version:
interface arrayconstructor { from<t, u>(arraylike: arraylike<t>, mapfn: (v: t, k: number) => u, thisarg?: any): array<u>; from<t>(arraylike: arraylike<t>): array<t>; } it's exact copy of how it's defined in lib.es6.d.ts.
Comments
Post a Comment