Skip to content

Commit 4389109

Browse files
authored
Fix shorthand property assignment type resolution (microsoft#646)
1 parent af508df commit 4389109

File tree

299 files changed

+576
-2995
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

299 files changed

+576
-2995
lines changed

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15027,7 +15027,7 @@ func (c *Checker) getTypeOfVariableOrParameterOrPropertyWorker(symbol *ast.Symbo
1502715027
case ast.KindPropertyAssignment:
1502815028
result = c.checkPropertyAssignment(declaration, CheckModeNormal)
1502915029
case ast.KindShorthandPropertyAssignment:
15030-
result = c.checkExpressionForMutableLocation(declaration, CheckModeNormal)
15030+
result = c.checkExpressionForMutableLocation(declaration.Name(), CheckModeNormal)
1503115031
case ast.KindMethodDeclaration:
1503215032
result = c.checkObjectLiteralMethod(declaration, CheckModeNormal)
1503315033
case ast.KindExportAssignment:

testdata/baselines/reference/submodule/compiler/abstractPropertyInConstructor.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ abstract class C1 {
276276
>({ x, y: y1, "y": y1 } = this) : this
277277
>{ x, y: y1, "y": y1 } = this : this
278278
>{ x, y: y1, "y": y1 } : { x: string; y: string; }
279-
>x : any
279+
>x : string
280280
>y : string
281281
>y1 : string
282282
>"y" : string
@@ -309,7 +309,7 @@ class C2 {
309309
>({ x, y: y1, "y": y1 } = this) : this
310310
>{ x, y: y1, "y": y1 } = this : this
311311
>{ x, y: y1, "y": y1 } : { x: string; y: string; }
312-
>x : any
312+
>x : string
313313
>y : string
314314
>y1 : string
315315
>"y" : string

testdata/baselines/reference/submodule/compiler/abstractPropertyInConstructor.types.diff

Lines changed: 0 additions & 20 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/argumentsAsPropertyName2.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function foo() {
3535
({ arguments });
3636
>({ arguments }) : { arguments: IArguments; }
3737
>{ arguments } : { arguments: IArguments; }
38-
>arguments : any
38+
>arguments : IArguments
3939

4040
({ arguments: arguments });
4141
>({ arguments: arguments }) : { arguments: IArguments; }

testdata/baselines/reference/submodule/compiler/argumentsAsPropertyName2.types.diff

Lines changed: 0 additions & 11 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/arrayBindingPatternOmittedExpressions.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ var results: string[];
1515
>{ a, b } : { a: string; b: string; }
1616

1717
a,
18-
>a : any
18+
>a : string
1919

2020
b
21-
>b : any
21+
>b : string
2222
}
2323
}
2424

testdata/baselines/reference/submodule/compiler/arrayBindingPatternOmittedExpressions.types.diff

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,7 @@
1010
>a : string
1111
>results : string[]
1212

13-
@@= skipped -11, +9 lines =@@
14-
>{ a, b } : { a: string; b: string; }
15-
16-
a,
17-
->a : string
18-
+>a : any
19-
20-
b
21-
->b : string
22-
+>b : any
23-
}
24-
}
13+
@@= skipped -20, +18 lines =@@
2514

2615

2716
function f([, a, , b, , , , s, , , ] = results) {

testdata/baselines/reference/submodule/compiler/arrayFromAsync.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,6 @@ const withIndexResult = await Array.fromAsync(["a", "b"], (str, index) => ({ ind
285285
>index : number
286286
>({ index, str }) : { index: number; str: string; }
287287
>{ index, str } : { index: number; str: string; }
288-
>index : any
289-
>str : any
288+
>index : number
289+
>str : string
290290

testdata/baselines/reference/submodule/compiler/arrayFromAsync.types.diff

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,3 @@
152152
>["a", "b"] : string[]
153153
>"a" : "a"
154154
>"b" : "b"
155-
@@= skipped -20, +20 lines =@@
156-
>index : number
157-
>({ index, str }) : { index: number; str: string; }
158-
>{ index, str } : { index: number; str: string; }
159-
->index : number
160-
->str : string
161-
+>index : any
162-
+>str : any
163-

testdata/baselines/reference/submodule/compiler/awaitedType.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ async function f17_usage() {
415415

416416
return { x };
417417
>{ x } : { x: 123; }
418-
>x : any
418+
>x : 123
419419
}
420420

421421
// https://github.com/microsoft/TypeScript/issues/47144

testdata/baselines/reference/submodule/compiler/awaitedType.types.diff

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,7 @@
153153
>args : any[]
154154
>fn : T
155155

156-
@@= skipped -33, +36 lines =@@
157-
158-
return { x };
159-
>{ x } : { x: 123; }
160-
->x : 123
161-
+>x : any
162-
}
163-
164-
// https://github.com/microsoft/TypeScript/issues/47144
165-
@@= skipped -8, +8 lines =@@
156+
@@= skipped -41, +44 lines =@@
166157
>GenericStructure : GenericStructure<AcceptableKeyType>
167158

168159
AcceptableKeyType extends string = string

testdata/baselines/reference/submodule/compiler/booleanLiteralsContextuallyTypedFromUnion.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ const c: C = isIt ? { isIt, text: 'hey' } : { isIt, value: 123 };
3030
>isIt ? { isIt, text: 'hey' } : { isIt, value: 123 } : { isIt: true; text: string; } | { isIt: false; value: number; }
3131
>isIt : boolean
3232
>{ isIt, text: 'hey' } : { isIt: true; text: string; }
33-
>isIt : any
33+
>isIt : true
3434
>text : string
3535
>'hey' : "hey"
3636
>{ isIt, value: 123 } : { isIt: false; value: number; }
37-
>isIt : any
37+
>isIt : false
3838
>value : number
3939
>123 : 123
4040

testdata/baselines/reference/submodule/compiler/booleanLiteralsContextuallyTypedFromUnion.types.diff

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,7 @@
1414
>isIt : false
1515
>false : false
1616
>value : number
17-
@@= skipped -26, +28 lines =@@
18-
>isIt ? { isIt, text: 'hey' } : { isIt, value: 123 } : { isIt: true; text: string; } | { isIt: false; value: number; }
19-
>isIt : boolean
20-
>{ isIt, text: 'hey' } : { isIt: true; text: string; }
21-
->isIt : true
22-
+>isIt : any
23-
>text : string
24-
>'hey' : "hey"
25-
>{ isIt, value: 123 } : { isIt: false; value: number; }
26-
->isIt : false
27-
+>isIt : any
28-
>value : number
29-
>123 : 123
30-
31-
@@= skipped -42, +42 lines =@@
17+
@@= skipped -68, +70 lines =@@
3218
};
3319

3420
let Funk = (_props: ComponentProps) => <div>Hello</div>;

testdata/baselines/reference/submodule/compiler/capturedParametersInInitializers1.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function foo4(y = {z}, z = 1) {
5050
>foo4 : (y?: { z: number; }, z?: number) => void
5151
>y : { z: number; }
5252
>{z} : { z: number; }
53-
>z : any
53+
>z : number
5454
>z : number
5555
>1 : 1
5656
}

testdata/baselines/reference/submodule/compiler/capturedParametersInInitializers1.types.diff

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,3 @@
3232
>a : any
3333
>z : number
3434
>1 : 1
35-
@@= skipped -17, +16 lines =@@
36-
>foo4 : (y?: { z: number; }, z?: number) => void
37-
>y : { z: number; }
38-
>{z} : { z: number; }
39-
+>z : any
40-
>z : number
41-
->z : number
42-
>1 : 1
43-
}
44-

testdata/baselines/reference/submodule/compiler/capturedShorthandPropertyAssignmentNoCheck.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ for (const value of [1, 2, 3]) {
2020
>() => ({ value }) : () => { value: number; }
2121
>({ value }) : { value: number; }
2222
>{ value } : { value: number; }
23-
>value : any
23+
>value : number
2424
}
2525
const result = fns.map(fn => fn());
2626
>result : any[]

testdata/baselines/reference/submodule/compiler/capturedShorthandPropertyAssignmentNoCheck.types.diff

Lines changed: 0 additions & 11 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/classExpressionTest1.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function M() {
2020

2121
return { t, x };
2222
>{ t, x } : { t: T; x: X; }
23-
>t : any
24-
>x : any
23+
>t : T
24+
>x : X
2525
}
2626
}
2727

testdata/baselines/reference/submodule/compiler/classExpressionTest1.types.diff

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,3 @@
1212

1313
var t: T;
1414
>t : T
15-
@@= skipped -12, +14 lines =@@
16-
17-
return { t, x };
18-
>{ t, x } : { t: T; x: X; }
19-
->t : T
20-
->x : X
21-
+>t : any
22-
+>x : any
23-
}
24-
}
25-

testdata/baselines/reference/submodule/compiler/classExpressionTest2.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function M() {
2222

2323
return { t, x };
2424
>{ t, x } : { t: T; x: X; }
25-
>t : any
26-
>x : any
25+
>t : T
26+
>x : X
2727
}
2828
}
2929

testdata/baselines/reference/submodule/compiler/classExpressionTest2.types.diff

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,3 @@
1212

1313
var t: T;
1414
>t : T
15-
@@= skipped -12, +14 lines =@@
16-
17-
return { t, x };
18-
>{ t, x } : { t: T; x: X; }
19-
->t : T
20-
->x : X
21-
+>t : any
22-
+>x : any
23-
}
24-
}
25-

testdata/baselines/reference/submodule/compiler/classPropInitializationInferenceWithElementAccess.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class Cls {
3434
>this : this
3535
>'y' : "y"
3636
>{ seed } : { seed: number; }
37-
>seed : any
37+
>seed : number
3838

3939
this['z'] = `${seed}`;
4040
>this['z'] = `${seed}` : string

testdata/baselines/reference/submodule/compiler/classPropInitializationInferenceWithElementAccess.types.diff

Lines changed: 0 additions & 11 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/coAndContraVariantInferences5.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ function f(
2121
>{ options, onChange, } : { options: SelectOptions<Thing>; onChange: (status: Thing | null) => void; }
2222

2323
options,
24-
>options : any
24+
>options : SelectOptions<Thing>
2525

2626
onChange,
27-
>onChange : any
27+
>onChange : (status: Thing | null) => void
2828

2929
});
3030
}

testdata/baselines/reference/submodule/compiler/coAndContraVariantInferences5.types.diff

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
--- old.coAndContraVariantInferences5.types
22
+++ new.coAndContraVariantInferences5.types
3-
@@= skipped -20, +20 lines =@@
4-
>{ options, onChange, } : { options: SelectOptions<Thing>; onChange: (status: Thing | null) => void; }
5-
6-
options,
7-
->options : SelectOptions<Thing>
8-
+>options : any
9-
10-
onChange,
11-
->onChange : (status: Thing | null) => void
12-
+>onChange : any
13-
14-
});
15-
}
3+
@@= skipped -30, +30 lines =@@
164

175
declare function select<KeyT extends string>(props: SelectProps<KeyT>): void;
186
>select : <KeyT extends string>(props: SelectProps<KeyT>) => void
@@ -25,7 +13,7 @@
2513

2614
options?: SelectOptions<KeyT>;
2715
>options : SelectOptions<KeyT> | undefined
28-
@@= skipped -26, +28 lines =@@
16+
@@= skipped -16, +18 lines =@@
2917

3018
type SelectOptions<KeyT extends string> =
3119
>SelectOptions : SelectOptions<KeyT>

testdata/baselines/reference/submodule/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export function makeNewChannel<T extends ChannelType>(type: T): NewChannel<Chann
7777

7878
return { type, localChannelId };
7979
>{ type, localChannelId } : { type: T; localChannelId: string; }
80-
>type : any
81-
>localChannelId : any
80+
>type : T
81+
>localChannelId : string
8282
}
8383

8484
const newTextChannel = makeNewChannel('text');

testdata/baselines/reference/submodule/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types.diff

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,7 @@
6464
>type : T
6565

6666
const localChannelId = `blahblahblah`;
67-
@@= skipped -15, +17 lines =@@
68-
69-
return { type, localChannelId };
70-
>{ type, localChannelId } : { type: T; localChannelId: string; }
71-
->type : T
72-
->localChannelId : string
73-
+>type : any
74-
+>localChannelId : any
75-
}
76-
67+
@@= skipped -22, +24 lines =@@
7768
const newTextChannel = makeNewChannel('text');
7869
>newTextChannel : NewChannel<TextChannel>
7970
>makeNewChannel('text') : NewChannel<TextChannel>
@@ -82,7 +73,7 @@
8273
>'text' : "text"
8374

8475
// This should work
85-
@@= skipped -21, +21 lines =@@
76+
@@= skipped -14, +14 lines =@@
8677
const newTextChannel2 : NewChannel<TextChannel> = makeNewChannel('text');
8778
>newTextChannel2 : NewChannel<TextChannel>
8879
>makeNewChannel('text') : NewChannel<TextChannel>

testdata/baselines/reference/submodule/compiler/contextualReturnTypeOfIIFE2.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ app.foo.bar = (function () {
2626

2727
return { someFun };
2828
>{ someFun } : { someFun: (arg: number) => void; }
29-
>someFun : any
29+
>someFun : (arg: number) => void
3030

3131
})();
3232

0 commit comments

Comments
 (0)