Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
86f69f1
Add test for the decorated method beginning with underscore
sheetalkamat Nov 30, 2016
e5b5fe1
When creating string literal for property access, unescape the identi…
sheetalkamat Nov 30, 2016
efe7b65
Merge pull request #12610 from Microsoft/Port12590
mhegazy Dec 1, 2016
edb376d
Update cli --target description (es2016 and 2017)
arusakov Dec 2, 2016
012159b
Merge pull request #12614 from arusakov/cli_targets_descriptions_es20…
mhegazy Dec 2, 2016
3b1d6c9
Treat indexed access types T[K] as type variables
ahejlsberg Dec 2, 2016
b3b2359
Accept new baselines
ahejlsberg Dec 2, 2016
1e2425e
Add tests
ahejlsberg Dec 2, 2016
fe0b66a
Accept new baselines
ahejlsberg Dec 2, 2016
a230cb7
Merge pull request #12623 from Microsoft/nestedIndexedAccess
ahejlsberg Dec 2, 2016
9310063
Fix elided syntax kinds falling through to visitConstructor in TypeSc…
MattiasBuelens Dec 3, 2016
c538f1f
Classify mapped type inferences as secondary
ahejlsberg Dec 3, 2016
773c9a7
Add tests
ahejlsberg Dec 3, 2016
970c4aa
Accept new baselines
ahejlsberg Dec 3, 2016
f61a224
Merge pull request #12639 from MattiasBuelens/fixElideFallthrough
DanielRosenwasser Dec 3, 2016
b876211
Property handle union/intersection types in type variable checks
ahejlsberg Dec 4, 2016
b4836e3
Add tests
ahejlsberg Dec 4, 2016
3aa05b2
Accept new baselines
ahejlsberg Dec 4, 2016
23992ba
Merge pull request #12640 from Microsoft/mappedTypesSecondaryInferences
ahejlsberg Dec 4, 2016
b7e8a6d
Merge pull request #12643 from Microsoft/keyofUnionIntersection
ahejlsberg Dec 4, 2016
c52eb6c
Indexed access any[K] has type any
ahejlsberg Dec 4, 2016
95aed3f
Add regression test
ahejlsberg Dec 4, 2016
ee172cf
Accept new baselines
ahejlsberg Dec 4, 2016
5c71de1
Merge pull request #12652 from Microsoft/fixIndexedAccessWithAny
ahejlsberg Dec 5, 2016
ae3b6e7
Merge branch 'master' into release-2.1
mhegazy Dec 5, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 91 additions & 83 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ namespace ts {
"es2017": ScriptTarget.ES2017,
"esnext": ScriptTarget.ESNext,
}),
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015,
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_or_ESNEXT,
paramType: Diagnostics.VERSION,
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2473,7 +2473,7 @@
"category": "Message",
"code": 6012
},
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015'": {
"Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'": {
"category": "Message",
"code": 6015
},
Expand Down
1 change: 1 addition & 0 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ namespace ts {

case SyntaxKind.PropertyDeclaration:
// TypeScript property declarations are elided.
return undefined;

case SyntaxKind.Constructor:
return visitConstructor(<ConstructorDeclaration>node);
Expand Down
27 changes: 18 additions & 9 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,7 @@ namespace ts {
UnionOrIntersection = Union | Intersection,
StructuredType = Object | Union | Intersection,
StructuredOrTypeParameter = StructuredType | TypeParameter | Index,
TypeVariable = TypeParameter | IndexedAccess,

// 'Narrowable' types are types where narrowing actually narrows.
// This *should* be every type other than null, undefined, void, and never
Expand Down Expand Up @@ -2907,7 +2908,9 @@ namespace ts {
/* @internal */
resolvedProperties: SymbolTable; // Cache of resolved properties
/* @internal */
couldContainTypeParameters: boolean;
resolvedIndexType: IndexType;
/* @internal */
couldContainTypeVariables: boolean;
}

export interface UnionType extends UnionOrIntersectionType { }
Expand Down Expand Up @@ -2963,8 +2966,13 @@ namespace ts {
iteratorElementType?: Type;
}

export interface TypeVariable extends Type {
/* @internal */
resolvedIndexType: IndexType;
}

// Type parameters (TypeFlags.TypeParameter)
export interface TypeParameter extends Type {
export interface TypeParameter extends TypeVariable {
constraint: Type; // Constraint
/* @internal */
target?: TypeParameter; // Instantiation target
Expand All @@ -2973,20 +2981,21 @@ namespace ts {
/* @internal */
resolvedApparentType: Type;
/* @internal */
resolvedIndexType: IndexType;
/* @internal */
isThisType?: boolean;
}

export interface IndexType extends Type {
type: TypeParameter;
}

export interface IndexedAccessType extends Type {
// Indexed access types (TypeFlags.IndexedAccess)
// Possible forms are T[xxx], xxx[T], or xxx[keyof T], where T is a type variable
export interface IndexedAccessType extends TypeVariable {
objectType: Type;
indexType: Type;
}

// keyof T types (TypeFlags.Index)
export interface IndexType extends Type {
type: TypeVariable | UnionOrIntersectionType;
}

export const enum SignatureKind {
Call,
Construct,
Expand Down
76 changes: 75 additions & 1 deletion tests/baselines/reference/isomorphicMappedTypeInference.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,39 @@ function f10(foo: Foo) {
let x = validate(foo); // { a: number, readonly b: string }
let y = clone(foo); // { a?: number, b: string }
let z = validateAndClone(foo); // { a: number, b: string }
}
}

// Repro from #12606

type Func<T> = (...args: any[]) => T;
type Spec<T> = {
[P in keyof T]: Func<T[P]> | Spec<T[P]> ;
};

/**
* Given a spec object recursively mapping properties to functions, creates a function
* producing an object of the same structure, by mapping each property to the result
* of calling its associated function with the supplied arguments.
*/
declare function applySpec<T>(obj: Spec<T>): (...args: any[]) => T;

// Infers g1: (...args: any[]) => { sum: number, nested: { mul: string } }
var g1 = applySpec({
sum: (a: any) => 3,
nested: {
mul: (b: any) => "n"
}
});

// Infers g2: (...args: any[]) => { foo: { bar: { baz: boolean } } }
var g2 = applySpec({ foo: { bar: { baz: (x: any) => true } } });

// Repro from #12633

const foo = <T>(object: T, partial: Partial<T>) => object;
let o = {a: 5, b: 7};
foo(o, {b: 9});
o = foo(o, {b: 9});

//// [isomorphicMappedTypeInference.js]
function box(x) {
Expand Down Expand Up @@ -210,6 +242,20 @@ function f10(foo) {
var y = clone(foo); // { a?: number, b: string }
var z = validateAndClone(foo); // { a: number, b: string }
}
// Infers g1: (...args: any[]) => { sum: number, nested: { mul: string } }
var g1 = applySpec({
sum: function (a) { return 3; },
nested: {
mul: function (b) { return "n"; }
}
});
// Infers g2: (...args: any[]) => { foo: { bar: { baz: boolean } } }
var g2 = applySpec({ foo: { bar: { baz: function (x) { return true; } } } });
// Repro from #12633
var foo = function (object, partial) { return object; };
var o = { a: 5, b: 7 };
foo(o, { b: 9 });
o = foo(o, { b: 9 });


//// [isomorphicMappedTypeInference.d.ts]
Expand Down Expand Up @@ -254,3 +300,31 @@ declare type Foo = {
readonly b: string;
};
declare function f10(foo: Foo): void;
declare type Func<T> = (...args: any[]) => T;
declare type Spec<T> = {
[P in keyof T]: Func<T[P]> | Spec<T[P]>;
};
/**
* Given a spec object recursively mapping properties to functions, creates a function
* producing an object of the same structure, by mapping each property to the result
* of calling its associated function with the supplied arguments.
*/
declare function applySpec<T>(obj: Spec<T>): (...args: any[]) => T;
declare var g1: (...args: any[]) => {
sum: number;
nested: {
mul: string;
};
};
declare var g2: (...args: any[]) => {
foo: {
bar: {
baz: boolean;
};
};
};
declare const foo: <T>(object: T, partial: Partial<T>) => T;
declare let o: {
a: number;
b: number;
};
94 changes: 94 additions & 0 deletions tests/baselines/reference/isomorphicMappedTypeInference.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,97 @@ function f10(foo: Foo) {
>validateAndClone : Symbol(validateAndClone, Decl(isomorphicMappedTypeInference.ts, 107, 69))
>foo : Symbol(foo, Decl(isomorphicMappedTypeInference.ts, 115, 13))
}

// Repro from #12606

type Func<T> = (...args: any[]) => T;
>Func : Symbol(Func, Decl(isomorphicMappedTypeInference.ts, 119, 1))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 123, 10))
>args : Symbol(args, Decl(isomorphicMappedTypeInference.ts, 123, 16))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 123, 10))

type Spec<T> = {
>Spec : Symbol(Spec, Decl(isomorphicMappedTypeInference.ts, 123, 37))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 124, 10))

[P in keyof T]: Func<T[P]> | Spec<T[P]> ;
>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 125, 5))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 124, 10))
>Func : Symbol(Func, Decl(isomorphicMappedTypeInference.ts, 119, 1))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 124, 10))
>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 125, 5))
>Spec : Symbol(Spec, Decl(isomorphicMappedTypeInference.ts, 123, 37))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 124, 10))
>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 125, 5))

};

/**
* Given a spec object recursively mapping properties to functions, creates a function
* producing an object of the same structure, by mapping each property to the result
* of calling its associated function with the supplied arguments.
*/
declare function applySpec<T>(obj: Spec<T>): (...args: any[]) => T;
>applySpec : Symbol(applySpec, Decl(isomorphicMappedTypeInference.ts, 126, 2))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 133, 27))
>obj : Symbol(obj, Decl(isomorphicMappedTypeInference.ts, 133, 30))
>Spec : Symbol(Spec, Decl(isomorphicMappedTypeInference.ts, 123, 37))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 133, 27))
>args : Symbol(args, Decl(isomorphicMappedTypeInference.ts, 133, 46))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 133, 27))

// Infers g1: (...args: any[]) => { sum: number, nested: { mul: string } }
var g1 = applySpec({
>g1 : Symbol(g1, Decl(isomorphicMappedTypeInference.ts, 136, 3))
>applySpec : Symbol(applySpec, Decl(isomorphicMappedTypeInference.ts, 126, 2))

sum: (a: any) => 3,
>sum : Symbol(sum, Decl(isomorphicMappedTypeInference.ts, 136, 20))
>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 137, 10))

nested: {
>nested : Symbol(nested, Decl(isomorphicMappedTypeInference.ts, 137, 23))

mul: (b: any) => "n"
>mul : Symbol(mul, Decl(isomorphicMappedTypeInference.ts, 138, 13))
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 139, 14))
}
});

// Infers g2: (...args: any[]) => { foo: { bar: { baz: boolean } } }
var g2 = applySpec({ foo: { bar: { baz: (x: any) => true } } });
>g2 : Symbol(g2, Decl(isomorphicMappedTypeInference.ts, 144, 3))
>applySpec : Symbol(applySpec, Decl(isomorphicMappedTypeInference.ts, 126, 2))
>foo : Symbol(foo, Decl(isomorphicMappedTypeInference.ts, 144, 20))
>bar : Symbol(bar, Decl(isomorphicMappedTypeInference.ts, 144, 27))
>baz : Symbol(baz, Decl(isomorphicMappedTypeInference.ts, 144, 34))
>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 144, 41))

// Repro from #12633

const foo = <T>(object: T, partial: Partial<T>) => object;
>foo : Symbol(foo, Decl(isomorphicMappedTypeInference.ts, 148, 5))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 148, 13))
>object : Symbol(object, Decl(isomorphicMappedTypeInference.ts, 148, 16))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 148, 13))
>partial : Symbol(partial, Decl(isomorphicMappedTypeInference.ts, 148, 26))
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 148, 13))
>object : Symbol(object, Decl(isomorphicMappedTypeInference.ts, 148, 16))

let o = {a: 5, b: 7};
>o : Symbol(o, Decl(isomorphicMappedTypeInference.ts, 149, 3))
>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 149, 9))
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 149, 14))

foo(o, {b: 9});
>foo : Symbol(foo, Decl(isomorphicMappedTypeInference.ts, 148, 5))
>o : Symbol(o, Decl(isomorphicMappedTypeInference.ts, 149, 3))
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 150, 8))

o = foo(o, {b: 9});
>o : Symbol(o, Decl(isomorphicMappedTypeInference.ts, 149, 3))
>foo : Symbol(foo, Decl(isomorphicMappedTypeInference.ts, 148, 5))
>o : Symbol(o, Decl(isomorphicMappedTypeInference.ts, 149, 3))
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 151, 12))

Loading