-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureFix AvailableA PR has been opened for this issueA PR has been opened for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 3.2
Search Terms: mapped tuples rest
Code
type FuncParams<T> = T extends (...args: infer P) => any ? P : never;
type Stringify<T> = {
[K in keyof T]: string;
};
type Optional<T> = {
[K in keyof T]?: T[K];
};
type ThreeParamFunc = (paramOne: string, paramTwo: number, paramThree: boolean) => void;
type Params = FuncParams<ThreeParamFunc>; // [string, number, boolean]
type StringParams = Stringify<FuncParams<ThreeParamFunc>>; // [string, string, string]
type OptionalParams = Optional<FuncParams<ThreeParamFunc>>; // [string?, number?, boolean?]
function doStuff<T>(func: T, ...params: FuncParams<T>) { // works fine
}
function doOptionalStuff<T>(func: T, ...params: Optional<FuncParams<T>>) { // A rest parameter must be of an array type.
}
function doStringStuff<T>(func: T, ...params: Stringify<FuncParams<T>>) { // A rest parameter must be of an array type.
}
Expected behavior:
I should be able to use a mapped tuple as a rest param in a function
Actual behavior:
I get the error A rest parameter must be of an array type.
Playground Link:
Link
tokland, YePpHa, OxleyS, vbfox, levenleven and 21 more
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureFix AvailableA PR has been opened for this issueA PR has been opened for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript