Skip to content

Commit

Permalink
Merge pull request #12670 from Microsoft/mergeMaster1205
Browse files Browse the repository at this point in the history
Merge master1205
  • Loading branch information
mhegazy committed Dec 5, 2016
2 parents a962176 + ae3b6e7 commit e15166a
Show file tree
Hide file tree
Showing 19 changed files with 2,053 additions and 139 deletions.
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

0 comments on commit e15166a

Please sign in to comment.