You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceArray<T>{// allow for all typesome(callbackfn: (value: T,index: number,array: T[])=>unknown,thisArg?: any): boolean;}interfaceArray<TwhenT is number>{// only when `T` is numbersum(): number;avg(): number;max(): number;min(): number;}
Use Cases
consta=['a','c','d'];// a.sum() // not allowedconstb=[1,2,5];constc=b.sum();// okconsole.log(c);// 8
Examples
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
Activity
[-]Generics conditional type[/-][+]Generics interface conditional type[/+]MartinJohns commentedon Aug 18, 2020
What about
Array<string | number>?mokeyish commentedon Aug 18, 2020
I write some extension methods for
Array, but it is not work as expectedly.mokeyish commentedon Aug 18, 2020
Currently , interface declarations with the same qualified name, it
Declaration Merginghttps://github.com/microsoft/TypeScript/blob/master/doc/spec.md#7.2
MartinJohns commentedon Aug 18, 2020
Please note that the spec is completely outdated and abandoned.
RyanCavanaugh commentedon Aug 19, 2020
You can already do this today; no new syntax is necessary:
mokeyish commentedon Aug 19, 2020
Ryan Cavanaugh (@RyanCavanaugh) Thanks!😁
