Skip to content

Commit e15166a

Browse files
authored
Merge pull request #12670 from Microsoft/mergeMaster1205
Merge master1205
2 parents a962176 + ae3b6e7 commit e15166a

19 files changed

+2053
-139
lines changed

src/compiler/checker.ts

+91-83
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ namespace ts {
272272
"es2017": ScriptTarget.ES2017,
273273
"esnext": ScriptTarget.ESNext,
274274
}),
275-
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015,
275+
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_or_ESNEXT,
276276
paramType: Diagnostics.VERSION,
277277
},
278278
{

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@
24732473
"category": "Message",
24742474
"code": 6012
24752475
},
2476-
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'": {
2476+
"Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'": {
24772477
"category": "Message",
24782478
"code": 6015
24792479
},

src/compiler/transformers/ts.ts

+1
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ namespace ts {
345345

346346
case SyntaxKind.PropertyDeclaration:
347347
// TypeScript property declarations are elided.
348+
return undefined;
348349

349350
case SyntaxKind.Constructor:
350351
return visitConstructor(<ConstructorDeclaration>node);

src/compiler/types.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -2797,6 +2797,7 @@ namespace ts {
27972797
UnionOrIntersection = Union | Intersection,
27982798
StructuredType = Object | Union | Intersection,
27992799
StructuredOrTypeParameter = StructuredType | TypeParameter | Index,
2800+
TypeVariable = TypeParameter | IndexedAccess,
28002801

28012802
// 'Narrowable' types are types where narrowing actually narrows.
28022803
// This *should* be every type other than null, undefined, void, and never
@@ -2907,7 +2908,9 @@ namespace ts {
29072908
/* @internal */
29082909
resolvedProperties: SymbolTable; // Cache of resolved properties
29092910
/* @internal */
2910-
couldContainTypeParameters: boolean;
2911+
resolvedIndexType: IndexType;
2912+
/* @internal */
2913+
couldContainTypeVariables: boolean;
29112914
}
29122915

29132916
export interface UnionType extends UnionOrIntersectionType { }
@@ -2963,8 +2966,13 @@ namespace ts {
29632966
iteratorElementType?: Type;
29642967
}
29652968

2969+
export interface TypeVariable extends Type {
2970+
/* @internal */
2971+
resolvedIndexType: IndexType;
2972+
}
2973+
29662974
// Type parameters (TypeFlags.TypeParameter)
2967-
export interface TypeParameter extends Type {
2975+
export interface TypeParameter extends TypeVariable {
29682976
constraint: Type; // Constraint
29692977
/* @internal */
29702978
target?: TypeParameter; // Instantiation target
@@ -2973,20 +2981,21 @@ namespace ts {
29732981
/* @internal */
29742982
resolvedApparentType: Type;
29752983
/* @internal */
2976-
resolvedIndexType: IndexType;
2977-
/* @internal */
29782984
isThisType?: boolean;
29792985
}
29802986

2981-
export interface IndexType extends Type {
2982-
type: TypeParameter;
2983-
}
2984-
2985-
export interface IndexedAccessType extends Type {
2987+
// Indexed access types (TypeFlags.IndexedAccess)
2988+
// Possible forms are T[xxx], xxx[T], or xxx[keyof T], where T is a type variable
2989+
export interface IndexedAccessType extends TypeVariable {
29862990
objectType: Type;
29872991
indexType: Type;
29882992
}
29892993

2994+
// keyof T types (TypeFlags.Index)
2995+
export interface IndexType extends Type {
2996+
type: TypeVariable | UnionOrIntersectionType;
2997+
}
2998+
29902999
export const enum SignatureKind {
29913000
Call,
29923001
Construct,

tests/baselines/reference/isomorphicMappedTypeInference.js

+75-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,39 @@ function f10(foo: Foo) {
118118
let x = validate(foo); // { a: number, readonly b: string }
119119
let y = clone(foo); // { a?: number, b: string }
120120
let z = validateAndClone(foo); // { a: number, b: string }
121-
}
121+
}
122+
123+
// Repro from #12606
124+
125+
type Func<T> = (...args: any[]) => T;
126+
type Spec<T> = {
127+
[P in keyof T]: Func<T[P]> | Spec<T[P]> ;
128+
};
129+
130+
/**
131+
* Given a spec object recursively mapping properties to functions, creates a function
132+
* producing an object of the same structure, by mapping each property to the result
133+
* of calling its associated function with the supplied arguments.
134+
*/
135+
declare function applySpec<T>(obj: Spec<T>): (...args: any[]) => T;
136+
137+
// Infers g1: (...args: any[]) => { sum: number, nested: { mul: string } }
138+
var g1 = applySpec({
139+
sum: (a: any) => 3,
140+
nested: {
141+
mul: (b: any) => "n"
142+
}
143+
});
144+
145+
// Infers g2: (...args: any[]) => { foo: { bar: { baz: boolean } } }
146+
var g2 = applySpec({ foo: { bar: { baz: (x: any) => true } } });
147+
148+
// Repro from #12633
149+
150+
const foo = <T>(object: T, partial: Partial<T>) => object;
151+
let o = {a: 5, b: 7};
152+
foo(o, {b: 9});
153+
o = foo(o, {b: 9});
122154

123155
//// [isomorphicMappedTypeInference.js]
124156
function box(x) {
@@ -210,6 +242,20 @@ function f10(foo) {
210242
var y = clone(foo); // { a?: number, b: string }
211243
var z = validateAndClone(foo); // { a: number, b: string }
212244
}
245+
// Infers g1: (...args: any[]) => { sum: number, nested: { mul: string } }
246+
var g1 = applySpec({
247+
sum: function (a) { return 3; },
248+
nested: {
249+
mul: function (b) { return "n"; }
250+
}
251+
});
252+
// Infers g2: (...args: any[]) => { foo: { bar: { baz: boolean } } }
253+
var g2 = applySpec({ foo: { bar: { baz: function (x) { return true; } } } });
254+
// Repro from #12633
255+
var foo = function (object, partial) { return object; };
256+
var o = { a: 5, b: 7 };
257+
foo(o, { b: 9 });
258+
o = foo(o, { b: 9 });
213259

214260

215261
//// [isomorphicMappedTypeInference.d.ts]
@@ -254,3 +300,31 @@ declare type Foo = {
254300
readonly b: string;
255301
};
256302
declare function f10(foo: Foo): void;
303+
declare type Func<T> = (...args: any[]) => T;
304+
declare type Spec<T> = {
305+
[P in keyof T]: Func<T[P]> | Spec<T[P]>;
306+
};
307+
/**
308+
* Given a spec object recursively mapping properties to functions, creates a function
309+
* producing an object of the same structure, by mapping each property to the result
310+
* of calling its associated function with the supplied arguments.
311+
*/
312+
declare function applySpec<T>(obj: Spec<T>): (...args: any[]) => T;
313+
declare var g1: (...args: any[]) => {
314+
sum: number;
315+
nested: {
316+
mul: string;
317+
};
318+
};
319+
declare var g2: (...args: any[]) => {
320+
foo: {
321+
bar: {
322+
baz: boolean;
323+
};
324+
};
325+
};
326+
declare const foo: <T>(object: T, partial: Partial<T>) => T;
327+
declare let o: {
328+
a: number;
329+
b: number;
330+
};

tests/baselines/reference/isomorphicMappedTypeInference.symbols

+94
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,97 @@ function f10(foo: Foo) {
393393
>validateAndClone : Symbol(validateAndClone, Decl(isomorphicMappedTypeInference.ts, 107, 69))
394394
>foo : Symbol(foo, Decl(isomorphicMappedTypeInference.ts, 115, 13))
395395
}
396+
397+
// Repro from #12606
398+
399+
type Func<T> = (...args: any[]) => T;
400+
>Func : Symbol(Func, Decl(isomorphicMappedTypeInference.ts, 119, 1))
401+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 123, 10))
402+
>args : Symbol(args, Decl(isomorphicMappedTypeInference.ts, 123, 16))
403+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 123, 10))
404+
405+
type Spec<T> = {
406+
>Spec : Symbol(Spec, Decl(isomorphicMappedTypeInference.ts, 123, 37))
407+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 124, 10))
408+
409+
[P in keyof T]: Func<T[P]> | Spec<T[P]> ;
410+
>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 125, 5))
411+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 124, 10))
412+
>Func : Symbol(Func, Decl(isomorphicMappedTypeInference.ts, 119, 1))
413+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 124, 10))
414+
>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 125, 5))
415+
>Spec : Symbol(Spec, Decl(isomorphicMappedTypeInference.ts, 123, 37))
416+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 124, 10))
417+
>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 125, 5))
418+
419+
};
420+
421+
/**
422+
* Given a spec object recursively mapping properties to functions, creates a function
423+
* producing an object of the same structure, by mapping each property to the result
424+
* of calling its associated function with the supplied arguments.
425+
*/
426+
declare function applySpec<T>(obj: Spec<T>): (...args: any[]) => T;
427+
>applySpec : Symbol(applySpec, Decl(isomorphicMappedTypeInference.ts, 126, 2))
428+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 133, 27))
429+
>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 133, 30))
430+
>Spec : Symbol(Spec, Decl(isomorphicMappedTypeInference.ts, 123, 37))
431+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 133, 27))
432+
>args : Symbol(args, Decl(isomorphicMappedTypeInference.ts, 133, 46))
433+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 133, 27))
434+
435+
// Infers g1: (...args: any[]) => { sum: number, nested: { mul: string } }
436+
var g1 = applySpec({
437+
>g1 : Symbol(g1, Decl(isomorphicMappedTypeInference.ts, 136, 3))
438+
>applySpec : Symbol(applySpec, Decl(isomorphicMappedTypeInference.ts, 126, 2))
439+
440+
sum: (a: any) => 3,
441+
>sum : Symbol(sum, Decl(isomorphicMappedTypeInference.ts, 136, 20))
442+
>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 137, 10))
443+
444+
nested: {
445+
>nested : Symbol(nested, Decl(isomorphicMappedTypeInference.ts, 137, 23))
446+
447+
mul: (b: any) => "n"
448+
>mul : Symbol(mul, Decl(isomorphicMappedTypeInference.ts, 138, 13))
449+
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 139, 14))
450+
}
451+
});
452+
453+
// Infers g2: (...args: any[]) => { foo: { bar: { baz: boolean } } }
454+
var g2 = applySpec({ foo: { bar: { baz: (x: any) => true } } });
455+
>g2 : Symbol(g2, Decl(isomorphicMappedTypeInference.ts, 144, 3))
456+
>applySpec : Symbol(applySpec, Decl(isomorphicMappedTypeInference.ts, 126, 2))
457+
>foo : Symbol(foo, Decl(isomorphicMappedTypeInference.ts, 144, 20))
458+
>bar : Symbol(bar, Decl(isomorphicMappedTypeInference.ts, 144, 27))
459+
>baz : Symbol(baz, Decl(isomorphicMappedTypeInference.ts, 144, 34))
460+
>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 144, 41))
461+
462+
// Repro from #12633
463+
464+
const foo = <T>(object: T, partial: Partial<T>) => object;
465+
>foo : Symbol(foo, Decl(isomorphicMappedTypeInference.ts, 148, 5))
466+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 148, 13))
467+
>object : Symbol(object, Decl(isomorphicMappedTypeInference.ts, 148, 16))
468+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 148, 13))
469+
>partial : Symbol(partial, Decl(isomorphicMappedTypeInference.ts, 148, 26))
470+
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
471+
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 148, 13))
472+
>object : Symbol(object, Decl(isomorphicMappedTypeInference.ts, 148, 16))
473+
474+
let o = {a: 5, b: 7};
475+
>o : Symbol(o, Decl(isomorphicMappedTypeInference.ts, 149, 3))
476+
>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 149, 9))
477+
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 149, 14))
478+
479+
foo(o, {b: 9});
480+
>foo : Symbol(foo, Decl(isomorphicMappedTypeInference.ts, 148, 5))
481+
>o : Symbol(o, Decl(isomorphicMappedTypeInference.ts, 149, 3))
482+
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 150, 8))
483+
484+
o = foo(o, {b: 9});
485+
>o : Symbol(o, Decl(isomorphicMappedTypeInference.ts, 149, 3))
486+
>foo : Symbol(foo, Decl(isomorphicMappedTypeInference.ts, 148, 5))
487+
>o : Symbol(o, Decl(isomorphicMappedTypeInference.ts, 149, 3))
488+
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 151, 12))
489+

0 commit comments

Comments
 (0)