-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Using destructuring in functions signatures is a relief, but when combining it with type declarations there is a lot of duplication necessary:
function foo(
{paramA, paramB, paramC, paramD = null}
:{paramA: number, paramB: string, paramC: boolean, paramD?: Object}
) {}
function bar(
[paramA, paramB, paramC, paramD]
:[number, string, boolean, Object]
) {}
Would it make sense to introduce the following syntax to reduce duplication of code?
function foo(
{paramA as number, paramB as string, paramC as boolean, paramD? as Object}
) {}
function bar(
[paramA as number, paramB as string, paramC as boolean, paramD as Object]
) {}
Originally I wanted to suggest to use the colon ":" instead of the "as", but since the colon is used for renaming destructured parametes, the "as" is the only option I guess.
With this syntax change the following would be possible too I guess:
let {paramA as number, paramB as string, paramC as boolean, paramD as Object} = anyObject;
let {paramA: a as number, paramB: b as string, paramC: c as boolean, paramD: d as Object} = anyObject;
let [paramA as number, paramB as string, paramC as boolean, paramD as Object] = anyArray;
cletusw, juanpicado, ErikCupal, tjpalmer, bradenhs and 12 more
Metadata
Metadata
Assignees
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript