-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Closed
SNiTEBoBy/TypeScript
#5Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
For typing something like underscore's _.chain, it would be helpful if interfaces could be extended based on the shape of their type parameters.
For example:
// These methods are available for any T.
declare interface Chainable<T> {
value(): T;
}
// These methods are only available for array types.
declare interface Chainable<T[]> {
map<U>(mapFn: (t: T) => U): Chainable<U[]>;
}Existing type definitions try to infer whether T is an array, object, array of objects, etc. But this is cumbersome and they'll never be able to do it as well as TypeScript itself.
The snippet above doesn't parse with TypeScript 2.1.5:
[ts] Operator '>' cannot be applied to types 'undefined[]' and '{ map<U>(mapFn: (t: any) => U): Chainable<U[]>; }'.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript