Skip to content

Commit 4fd6127

Browse files
committed
Partially revert microsoft#41044, restoring parameter destructurings in d.ts files (microsoft#50779)
1 parent 48a38ff commit 4fd6127

26 files changed

+190
-129
lines changed

src/compiler/checker.ts

+9-19
Original file line numberDiff line numberDiff line change
@@ -6094,29 +6094,19 @@ namespace ts {
60946094
return parameterNode;
60956095

60966096
function cloneBindingName(node: BindingName): BindingName {
6097-
return elideInitializerAndPropertyRenamingAndSetEmitFlags(node) as BindingName;
6098-
function elideInitializerAndPropertyRenamingAndSetEmitFlags(node: Node): Node {
6097+
return elideInitializerAndSetEmitFlags(node) as BindingName;
6098+
function elideInitializerAndSetEmitFlags(node: Node): Node {
60996099
if (context.tracker.trackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) {
61006100
trackComputedName(node.expression, context.enclosingDeclaration, context);
61016101
}
6102-
let visited = visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags)!;
6102+
let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!;
61036103
if (isBindingElement(visited)) {
6104-
if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name) && !isStringAKeyword(idText(visited.propertyName))) {
6105-
visited = factory.updateBindingElement(
6106-
visited,
6107-
visited.dotDotDotToken,
6108-
/* propertyName*/ undefined,
6109-
visited.propertyName,
6110-
/*initializer*/ undefined);
6111-
}
6112-
else {
6113-
visited = factory.updateBindingElement(
6114-
visited,
6115-
visited.dotDotDotToken,
6116-
visited.propertyName,
6117-
visited.name,
6118-
/*initializer*/ undefined);
6119-
}
6104+
visited = factory.updateBindingElement(
6105+
visited,
6106+
visited.dotDotDotToken,
6107+
visited.propertyName,
6108+
visited.name,
6109+
/*initializer*/ undefined);
61206110
}
61216111
if (!nodeIsSynthesized(visited)) {
61226112
visited = factory.cloneNode(visited);

tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface Show {
55
>x : number
66
}
77
function f({ show: showRename = v => v }: Show) {}
8-
>f : ({ show }: Show) => void
8+
>f : ({ show: showRename }: Show) => void
99
>show : any
1010
>showRename : (x: number) => string
1111
>v => v : (v: number) => number
@@ -32,7 +32,7 @@ interface Nested {
3232
>nested : Show
3333
}
3434
function ff({ nested: nestedRename = { show: v => v } }: Nested) {}
35-
>ff : ({ nested }: Nested) => void
35+
>ff : ({ nested: nestedRename }: Nested) => void
3636
>nested : any
3737
>nestedRename : Show
3838
>{ show: v => v } : { show: (v: number) => number; }

tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ export interface GetLocalesOptions<T extends LocaleData> {
4444
config?: LocaleConfig<T> | undefined;
4545
name?: string;
4646
}
47-
export declare const getLocales: <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>;
47+
export declare const getLocales: <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>;
4848
export {};

tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export interface GetLocalesOptions<T extends LocaleData> {
2626
}
2727

2828
export const getLocales = <T extends LocaleData>({
29-
>getLocales : <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>
30-
><T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig = {},}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => { return defaultLocalesConfig;} : <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>
29+
>getLocales : <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>
30+
><T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig = {},}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => { return defaultLocalesConfig;} : <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>
3131

3232
app,
3333
>app : unknown

tests/baselines/reference/declarationEmitBindingPatterns.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function f(_a, _b, _c) {
1818

1919

2020
//// [declarationEmitBindingPatterns.d.ts]
21-
declare const k: ({ x }: {
21+
declare const k: ({ x: z }: {
2222
x?: string;
2323
}) => void;
2424
declare var a: any;

tests/baselines/reference/declarationEmitBindingPatterns.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== tests/cases/compiler/declarationEmitBindingPatterns.ts ===
22
const k = ({x: z = 'y'}) => { }
3-
>k : ({ x }: { x?: string; }) => void
4-
>({x: z = 'y'}) => { } : ({ x }: { x?: string; }) => void
3+
>k : ({ x: z }: { x?: string; }) => void
4+
>({x: z = 'y'}) => { } : ({ x: z }: { x?: string; }) => void
55
>x : any
66
>z : string
77
>'y' : "y"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [declarationEmitDuplicateParameterDestructuring.ts]
2+
export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b;
3+
4+
export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b;
5+
6+
7+
8+
9+
//// [declarationEmitDuplicateParameterDestructuring.d.ts]
10+
export declare const fn1: ({ prop: a, prop: b }: {
11+
prop: number;
12+
}) => number;
13+
export declare const fn2: ({ prop: a }: {
14+
prop: number;
15+
}, { prop: b }: {
16+
prop: number;
17+
}) => number;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts ===
2+
export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b;
3+
>fn1 : Symbol(fn1, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 12))
4+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43))
5+
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 21))
6+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43))
7+
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 30))
8+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43))
9+
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 21))
10+
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 30))
11+
12+
export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b;
13+
>fn2 : Symbol(fn2, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 12))
14+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 34))
15+
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 21))
16+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 34))
17+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 65))
18+
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 52))
19+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 65))
20+
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 21))
21+
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 52))
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts ===
2+
export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b;
3+
>fn1 : ({ prop: a, prop: b }: { prop: number;}) => number
4+
>({ prop: a, prop: b }: { prop: number }) => a + b : ({ prop: a, prop: b }: { prop: number;}) => number
5+
>prop : any
6+
>a : number
7+
>prop : any
8+
>b : number
9+
>prop : number
10+
>a + b : number
11+
>a : number
12+
>b : number
13+
14+
export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b;
15+
>fn2 : ({ prop: a }: { prop: number;}, { prop: b }: { prop: number;}) => number
16+
>({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b : ({ prop: a }: { prop: number;}, { prop: b }: { prop: number;}) => number
17+
>prop : any
18+
>a : number
19+
>prop : number
20+
>prop : any
21+
>b : number
22+
>prop : number
23+
>a + b : number
24+
>a : number
25+
>b : number
26+

tests/baselines/reference/declarationsAndAssignments.types

+4-4
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ function f13() {
417417
}
418418

419419
function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
420-
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
420+
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
421421
>a : number
422422
>1 : 1
423423
>b : string
@@ -438,7 +438,7 @@ function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
438438
}
439439
f14([2, ["abc", { x: 0, y: true }]]);
440440
>f14([2, ["abc", { x: 0, y: true }]]) : void
441-
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
441+
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
442442
>[2, ["abc", { x: 0, y: true }]] : [number, [string, { x: number; y: true; }]]
443443
>2 : 2
444444
>["abc", { x: 0, y: true }] : [string, { x: number; y: true; }]
@@ -451,7 +451,7 @@ f14([2, ["abc", { x: 0, y: true }]]);
451451

452452
f14([2, ["abc", { x: 0 }]]);
453453
>f14([2, ["abc", { x: 0 }]]) : void
454-
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
454+
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
455455
>[2, ["abc", { x: 0 }]] : [number, [string, { x: number; }]]
456456
>2 : 2
457457
>["abc", { x: 0 }] : [string, { x: number; }]
@@ -462,7 +462,7 @@ f14([2, ["abc", { x: 0 }]]);
462462

463463
f14([2, ["abc", { y: false }]]); // Error, no x
464464
>f14([2, ["abc", { y: false }]]) : void
465-
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
465+
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
466466
>[2, ["abc", { y: false }]] : [number, [string, { y: false; }]]
467467
>2 : 2
468468
>["abc", { y: false }] : [string, { y: false; }]

tests/baselines/reference/destructuringInFunctionType.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type T3 = ([{ a: b }, { b: a }]);
3131
>b : a
3232

3333
type F3 = ([{ a: b }, { b: a }]) => void;
34-
>F3 : ([{ a }, { b }]: [{ a: any; }, { b: any; }]) => void
34+
>F3 : ([{ a: b }, { b: a }]: [{ a: any; }, { b: any; }]) => void
3535
>a : any
3636
>b : any
3737
>b : any

tests/baselines/reference/destructuringParameterDeclaration1ES5.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ d5(); // Parameter is optional as its declaration included an initializer
402402
// Type annotations must instead be written on the top- level parameter declaration
403403

404404
function e1({x: number}) { } // x has type any NOT number
405-
>e1 : ({ x }: { x: any; }) => void
405+
>e1 : ({ x: number }: { x: any; }) => void
406406
>x : any
407407
>number : any
408408

tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ d5(); // Parameter is optional as its declaration included an initializer
402402
// Type annotations must instead be written on the top- level parameter declaration
403403

404404
function e1({x: number}) { } // x has type any NOT number
405-
>e1 : ({ x }: { x: any; }) => void
405+
>e1 : ({ x: number }: { x: any; }) => void
406406
>x : any
407407
>number : any
408408

tests/baselines/reference/destructuringParameterDeclaration1ES6.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ d5(); // Parameter is optional as its declaration included an initializer
376376
// Type annotations must instead be written on the top- level parameter declaration
377377

378378
function e1({x: number}) { } // x has type any NOT number
379-
>e1 : ({ x }: { x: any; }) => void
379+
>e1 : ({ x: number }: { x: any; }) => void
380380
>x : any
381381
>number : any
382382

tests/baselines/reference/excessPropertyCheckWithSpread.types

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/compiler/excessPropertyCheckWithSpread.ts ===
22
declare function f({ a: number }): void
3-
>f : ({ a }: { a: any; }) => void
3+
>f : ({ a: number }: { a: any; }) => void
44
>a : any
55
>number : any
66

@@ -13,7 +13,7 @@ declare let i: I;
1313

1414
f({ a: 1, ...i });
1515
>f({ a: 1, ...i }) : void
16-
>f : ({ a }: { a: any; }) => void
16+
>f : ({ a: number }: { a: any; }) => void
1717
>{ a: 1, ...i } : { n: number; a: number; }
1818
>a : number
1919
>1 : 1
@@ -35,7 +35,7 @@ declare let r: R;
3535

3636
f({ a: 1, ...l, ...r });
3737
>f({ a: 1, ...l, ...r }) : void
38-
>f : ({ a }: { a: any; }) => void
38+
>f : ({ a: number }: { a: any; }) => void
3939
>{ a: 1, ...l, ...r } : { opt: string | number; a: number; }
4040
>a : number
4141
>1 : 1

tests/baselines/reference/objectRestParameter.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void);
1919
suddenly(({ x: a, ...rest }) => rest.y);
2020
>suddenly(({ x: a, ...rest }) => rest.y) : any
2121
>suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any
22-
>({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
22+
>({ x: a, ...rest }) => rest.y : ({ x: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
2323
>x : any
2424
>a : { z: any; ka: any; }
2525
>rest : { y: string; }

tests/baselines/reference/objectRestParameterES5.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void);
1919
suddenly(({ x: a, ...rest }) => rest.y);
2020
>suddenly(({ x: a, ...rest }) => rest.y) : any
2121
>suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any
22-
>({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
22+
>({ x: a, ...rest }) => rest.y : ({ x: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
2323
>x : any
2424
>a : { z: any; ka: any; }
2525
>rest : { y: string; }

tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,18 @@ interface I {
167167
}): any;
168168
}
169169
declare function f1({ a }: O): void;
170-
declare const f2: ({ a }: O) => void;
171-
declare const f3: ({ a, b, c }: O) => void;
172-
declare const f4: ({ a }: O) => string;
173-
declare const f5: ({ a, b, c }: O) => string;
170+
declare const f2: ({ a: string }: O) => void;
171+
declare const f3: ({ a: string, b, c }: O) => void;
172+
declare const f4: ({ a: string }: O) => string;
173+
declare const f5: ({ a: string, b, c }: O) => string;
174174
declare const obj1: {
175-
method({ a }: O): void;
175+
method({ a: string }: O): void;
176176
};
177177
declare const obj2: {
178-
method({ a }: O): string;
178+
method({ a: string }: O): string;
179179
};
180180
declare function f6({ a }: O): void;
181-
declare const f7: ({ a, b, c }: O) => void;
181+
declare const f7: ({ a: string, b, c }: O) => void;
182182
declare const f8: ({ "a": string }: O) => void;
183183
declare function f9({ 2: string }: {
184184
2: any;

0 commit comments

Comments
 (0)