Merge branch 'master' into letAndConst

Conflicts:
	src/compiler/types.ts
This commit is contained in:
Mohamed Hegazy 2014-10-16 09:30:58 -07:00
commit e15f4e6d34
252 changed files with 5629 additions and 4962 deletions

View File

@ -9,7 +9,7 @@ Design changes will not be accepted at this time. If you have a design change pr
## Legal
You will need to complete a Contributor License Agreement (CLA). Briefly, this agreement testifies that you are granting us permission to use the submitted change according to the terms of the project's license, and that the work being submitted is under appropriate copyright.
Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190)), sign, scan, and email it back to <cla@microsoft.com>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features.
Please submit a Contributor License Agreement (CLA) before submitting a pull request. Download the agreement ([Microsoft Contribution License Agreement.docx](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=822190) or [Microsoft Contribution License Agreement.pdf](https://www.codeplex.com/Download?ProjectName=typescript&DownloadId=921298)), sign, scan, and email it back to <cla@microsoft.com>. Be sure to include your github user name along with the agreement. Once we have received the signed CLA, we'll review the request. Please note that we're currently only accepting pull requests of bug fixes rather than new features.
## Housekeeping
Your pull request should:

View File

@ -1,8 +1,8 @@
# TypeScript Language Specification
Version 1.3
Version 1.4
September, 2014
October, 2014
<br/>
@ -45,9 +45,10 @@ TypeScript is a trademark of Microsoft Corporation.
* [3.3.1 Named Type References](#3.3.1)
* [3.3.2 Array Types](#3.3.2)
* [3.3.3 Tuple Types](#3.3.3)
* [3.3.4 Function Types](#3.3.4)
* [3.3.5 Constructor Types](#3.3.5)
* [3.3.6 Members](#3.3.6)
* [3.3.4 Union Types](#3.3.4)
* [3.3.5 Function Types](#3.3.5)
* [3.3.6 Constructor Types](#3.3.6)
* [3.3.7 Members](#3.3.7)
* [3.4 Type Parameters](#3.4)
* [3.4.1 Type Parameter Lists](#3.4.1)
* [3.4.2 Type Argument Lists](#3.4.2)
@ -59,9 +60,10 @@ TypeScript is a trademark of Microsoft Corporation.
* [3.6.3 Object Type Literals](#3.6.3)
* [3.6.4 Array Type Literals](#3.6.4)
* [3.6.5 Tuple Type Literals](#3.6.5)
* [3.6.6 Function Type Literals](#3.6.6)
* [3.6.7 Constructor Type Literals](#3.6.7)
* [3.6.8 Type Queries](#3.6.8)
* [3.6.6 Union Type Literals](#3.6.6)
* [3.6.7 Function Type Literals](#3.6.7)
* [3.6.8 Constructor Type Literals](#3.6.8)
* [3.6.9 Type Queries](#3.6.9)
* [3.7 Specifying Members](#3.7)
* [3.7.1 Property Signatures](#3.7.1)
* [3.7.2 Call Signatures](#3.7.2)
@ -77,7 +79,6 @@ TypeScript is a trademark of Microsoft Corporation.
* [3.8.6 Type Inference](#3.8.6)
* [3.8.7 Recursive Types](#3.8.7)
* [3.9 Widened Types](#3.9)
* [3.10 Best Common Type](#3.10)
* [4 Expressions](#4)
* [4.1 Values and References](#4.1)
* [4.2 The this Keyword](#4.2)
@ -119,6 +120,7 @@ TypeScript is a trademark of Microsoft Corporation.
* [4.17 Assignment Operators](#4.17)
* [4.18 The Comma Operator](#4.18)
* [4.19 Contextually Typed Expressions](#4.19)
* [4.20 Type Guards](#4.20)
* [5 Statements](#5)
* [5.1 Variable Statements](#5.1)
* [5.2 If, Do, and While Statements](#5.2)
@ -1049,13 +1051,14 @@ All string literal types are subtypes of the String primitive type.
Object types are composed from properties, call signatures, construct signatures, and index signatures, collectively called members.
Class and interface type references, array types, tuple types, function types, and constructor types are all classified as object types. Multiple constructs in the TypeScript language create object types, including:
Class and interface type references, array types, tuple types, union types, function types, and constructor types are all classified as object types. Multiple constructs in the TypeScript language create object types, including:
* Object type literals (section [3.6.3](#3.6.3)).
* Array type literals (section [3.6.4](#3.6.4)).
* Tuple type literals (section [3.6.5](#3.6.5)).
* Function type literals (section [3.6.6](#3.6.6)).
* Constructor type literals (section [3.6.7](#3.6.7)).
* Union type literals (section [3.6.6](#3.6.6)).
* Function type literals (section [3.6.7](#3.6.7)).
* Constructor type literals (section [3.6.8](#3.6.8)).
* Object literals (section [4.5](#4.5)).
* Array literals (section [4.6](#4.6)).
* Function expressions (section [4.9](#4.9)) and function declarations ([6.1](#6.1)).
@ -1105,23 +1108,111 @@ combines the set of properties
}
```
with the members of an array type whose element type is the best common type (section [3.10](#3.10)) of the tuple element types.
with the members of an array type whose element type is the union type (section [3.3.4](#3.3.4)) of the tuple element types.
Array literals (section [4.6](#4.6)) may be used to create values of tuple types. For example
Array literals (section [4.6](#4.6)) may be used to create values of tuple types.
An example:
```TypeScript
var t: [number, string] = [1, "one"];
var t: [number, string] = [3, "three"];
var n = t[0]; // Type of n is number
var s = t[1]; // Type of s is string
var i: number;
var x = t[i]; // Type of x is number | string
```
### <a name="3.3.4"/>3.3.4 Function Types
### <a name="3.3.4"/>3.3.4 Union Types
An object type containing one or more call signatures is said to be a ***function type***. Function types may be written using function type literals (section [3.6.6](#3.6.6)) or by including call signatures in object type literals.
***Union types*** represent values that may have one of several disjoint representations. A value of a union type *A* | *B* is a value that is *either* of type *A* or type *B*. Union types are written using union type literals (section [3.6.6](#3.6.6)).
### <a name="3.3.5"/>3.3.5 Constructor Types
A union type encompasses an unordered set of unrelated types (that is, types that arent subtypes of each other). The following rules govern union types:
An object type containing one or more construct signatures is said to be a ***constructor type***. Constructor types may be written using constructor type literals (section [3.6.7](#3.6.7)) or by including construct signatures in object type literals.
* *A* | *B* is equivalent to *A* if *B* is a subtype of *A*.
* *A* | *B* is equivalent to *B* | *A*.
* *AB* | *C* is equivalent to *A* | *BC*, where *AB* is *A* | *B* and *BC* is *B* | *C*.
### <a name="3.3.6"/>3.3.6 Members
Union types are reduced to the smallest possible set of constituent types using these rules.
Union types have the following subtype relationships:
* A union type *U* is a subtype of a type *T* if each type in *U* is a subtype of *T*.
* A type *T* is a subtype of a union type *U* if *T* is a subtype of any type in *U*.
Similarly, union types have the following assignability relationships:
* A union type *U* is assignable to a type *T* if each type in *U* is assignable to *T*.
* A type *T* is assignable to a union type *U* if *T* is assignable to any type in *U*.
For purposes of property access (section [4.10](#4.10)) and function calls ([4.12](#4.12)), a union type *U* has those members that are present in every one of its constituent types, with types that are unions of the respective members in the constituent types. Specifically:
* If each type in *U* has a property *P*, *U* has a property *P* of a union type of the types of *P* from each type in *U*.
* If each type in *U* has call signatures and the sets of call signatures are identical ignoring return types, *U* has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in *U*.
* If each type in *U* has construct signatures and the sets of construct signatures are identical ignoring return types, *U* has the same set of construct signatures, but with return types that are unions of the return types of the respective construct signatures from each type in *U*.
* If each type in *U* has a string index signature, *U* has a string index signature of a union type of the types of the string index signatures from each type in *U*.
* If each type in *U* has a numeric index signature, *U* has a numeric index signature of a union type of the types of the numeric index signatures from each type in *U*.
When used as a contextual type (section [4.19](#4.19)), a union type *U* has those members that are present in any of its constituent types, with types that are unions of the respective members in the constituent types. Specifically:
* Let *S* be the set of types in *U* that has a property *P*. If *S* is not empty, *U* has a property *P* of a union type of the types of *P* from each type in *S*.
* Let *S* be the set of types in *U* that have call signatures. If *S* is not empty and the sets of call signatures of the types in *S* are identical ignoring return types,* U* has the same set of call signatures, but with return types that are unions of the return types of the respective call signatures from each type in *S*.
* Let *S* be the set of types in *U* that have construct signatures. If *S* is not empty and the sets of construct signatures of the types in *S* are identical ignoring return types,* U* has the same set of construct signatures, but with return types that are unions of the return types of the respective construct signatures from each type in *S*.
* Let *S* be the set of types in *U* that has a string index signature. If *S* is not empty, *U* has a string index signature of a union type of the types of the string index signatures from each type in *S*.
* Let *S* be the set of types in *U* that has a numeric index signature. If *S* is not empty, *U* has a numeric index signature of a union type of the types of the numeric index signatures from each type in *S*.
The || and conditional operators (section [4.15.7](#4.15.7) and [4.16](#4.16)) may produce values of union types, and array literals (section [4.6](#4.6)) may produce array values that have union types as their element types.
Type guards (section [4.20](#4.20)) may be used to narrow a union type to a more specific type. In particular, type guards are useful for narrowing union type values to a non-union type values.
In the example
```TypeScript
var x: string | number;
var test: boolean;
x = "hello"; // Ok
x = 42; // Ok
x = test; // Error, boolean not assignable
x = test ? 5 : "five"; // Ok
x = test ? 0 : false; // Error, number | boolean not asssignable
```
it is possible to assign x a value of type string, number, or the union type string | number, but not any other type. To access a value in x, a type guard can be used to first narrow the type of x to either string or number:
```TypeScript
var n = typeof x === "string" ? x.length : x; // Type of n is number
```
The following example illustrates the merging of member types that occurs when union types are created from object types.
```TypeScript
interface A {
a: string;
b: number;
}
interface B {
a: number;
b: number;
c: number;
}
var x: A | B;
var a = x.a; // a has type string | number
var b = x.b; // b has type number
var c = x.c; // Error, no property c in union type
```
Note that x.a has a union type because the type of a is different in A and B, whereas x.b simply has type number because that is the type of b in both A and B. Also note that there is no property x.c because only A has a property c.
### <a name="3.3.5"/>3.3.5 Function Types
An object type containing one or more call signatures is said to be a ***function type***. Function types may be written using function type literals (section [3.6.7](#3.6.7)) or by including call signatures in object type literals.
### <a name="3.3.6"/>3.3.6 Constructor Types
An object type containing one or more construct signatures is said to be a ***constructor type***. Constructor types may be written using constructor type literals (section [3.6.8](#3.6.8)) or by including construct signatures in object type literals.
### <a name="3.3.7"/>3.3.7 Members
Every object type is composed from zero or more of the following kinds of members:
@ -1263,6 +1354,7 @@ Types are specified either by referencing their keyword or name, or by writing o
&emsp;&emsp;&emsp;*ObjectType*
&emsp;&emsp;&emsp;*ArrayType*
&emsp;&emsp;&emsp;*TupleType*
&emsp;&emsp;&emsp;*UnionType*
&emsp;&emsp;&emsp;*FunctionType*
&emsp;&emsp;&emsp;*ConstructorType*
&emsp;&emsp;&emsp;*TypeQuery*
@ -1381,7 +1473,7 @@ An array type literal is written as an element type followed by an open and clos
An array type literal references an array type (section [3.3.2](#3.3.2)) with the given element type. An array type literal is simply shorthand notation for a reference to the generic interface type Array in the global module with the element type as a type argument.
In order to avoid grammar ambiguities, array type literals permit only a restricted set of notations for the element type. Specifically, an *ArrayType* cannot start with a *FunctionType* or *ConstructorType*. To use one of those forms for the element type, an array type must be written using the Array&lt;T> notation. For example, the type
In order to avoid grammar ambiguities, array type literals permit only a restricted set of notations for the element type. Specifically, an *ArrayType* cannot start with a *UnionType*, *FunctionType* or *ConstructorType*. To use one of those forms for the element type, an array type must be written using the Array&lt;T> notation. For example, the type
```TypeScript
() => string[]
@ -1415,7 +1507,34 @@ A tuple type literal is written as a sequence of element types, separated by com
A tuple type literal references a tuple type (section [3.3.3](#3.3.3)).
### <a name="3.6.6"/>3.6.6 Function Type Literals
### <a name="3.6.6"/>3.6.6 Union Type Literals
A union type literal is written as a sequence of types separated by vertical bars.
&emsp;&emsp;*UnionType:*
&emsp;&emsp;&emsp;*ElementType*&emsp;`|`&emsp;*UnionOrElementType*
&emsp;&emsp;*UnionOrElementType:*
&emsp;&emsp;&emsp;*UnionType*
&emsp;&emsp;&emsp;*ElementType*
A union typle literal references a union type (section [3.3.4](#3.3.4)).
In order to avoid grammar ambiguities, union type literals permit only a restricted set of notations for the element types. Specifically, an element of a *UnionType* cannot be written as a *FunctionType* or *ConstructorType*. To include function or constructor types in a union type the function or constructor types must be written as object type literals. For example
```TypeScript
() => string | () => number
```
denotes a function whose return value is either a string or a function returning number, whereas
```TypeScript
{ (): string } | { (): number }
```
denotes either a function returning string or a function returning number.
### <a name="3.6.7"/>3.6.7 Function Type Literals
A function type literal specifies the type parameters, regular parameters, and return type of a call signature.
@ -1436,7 +1555,7 @@ is exactly equivalent to the object type literal
Note that function types with multiple call or construct signatures cannot be written as function type literals but must instead be written as object type literals.
### <a name="3.6.7"/>3.6.7 Constructor Type Literals
### <a name="3.6.8"/>3.6.8 Constructor Type Literals
A constructor type literal specifies the type parameters, regular parameters, and return type of a construct signature.
@ -1457,7 +1576,7 @@ is exactly equivalent to the object type literal
Note that constructor types with multiple construct signatures cannot be written as constructor type literals but must instead be written as object type literals.
### <a name="3.6.8"/>3.6.8 Type Queries
### <a name="3.6.9"/>3.6.9 Type Queries
A type query obtains the type of an expression.
@ -1775,8 +1894,9 @@ Two types are considered ***identical*** when
* they are both the Any type,
* they are the same primitive type,
* they are the same type parameter, or
* they are object types with identical sets of members.
* they are the same type parameter,
* they are union types with identical sets of constituent types, or
* they are non-union object types with identical sets of members.
Two members are considered identical when
@ -1816,6 +1936,8 @@ the variables
* *S* is an enum type and *T* is the primitive type Number.
* *S* is a string literal type and *T* is the primitive type String.
* *S* and *T* are type parameters, and *S* is directly or indirectly constrained to *T*.
* *S* is a union type and each constituent type of *S* is a subtype of *T*.
* *T* is a union type and *S* is a subtype of at least one constituent type of *T*.
* *S* and *T* are object types and, for each member *M* in *T*, one of the following is true:
* *M* is a property and *S* contains a property *N* where
* *M* and *N* have the same name,
@ -1850,6 +1972,8 @@ Types are required to be assignment compatible in certain circumstances, such as
* *S* or *T* is an enum type and* *the other is the primitive type Number.
* *S* is a string literal type and *T* is the primitive type String.
* *S* and *T* are type parameters, and *S* is directly or indirectly constrained to *T*.
* *S* is a union type and each constituent type of *S* is assignable to *T*.
* *T* is a union type and *S* is assignable to at least one constituent type of *T*.
* *S* and *T* are object types and, for each member *M* in *T*, one of the following is true:
* *M* is a property and *S* contains a property *N* where
* *M* and *N* have the same name,
@ -1890,13 +2014,18 @@ foo({ name: "hello" }); // Error, id required but missing
During type argument inference in a function call (section [4.12.2](#4.12.2)) it is in certain circumstances necessary to instantiate a generic call signature of an argument expression in the context of a non-generic call signature of a parameter such that further inferences can be made. A generic call signature *A* is ***instantiated in the context of*** non-generic call signature *B* as follows:
* Using the process described in [3.8.6](#3.8.6), inferences for *A*s type parameters are made from each parameter type in *B* to the corresponding parameter type in *A* for those parameter positions that are present in both signatures, where rest parameters correspond to an unbounded expansion of optional parameters of the rest parameter element type.
* The inferred type argument for each type parameter is the best common type (section [3.10](#3.10)) of the set of inferences made for that type parameter. However, if the best common type does not satisfy the constraint of the type parameter, the inferred type argument is instead the constraint.
* The inferred type argument for each type parameter is the union type of the set of inferences made for that type parameter. However, if the union type does not satisfy the constraint of the type parameter, the inferred type argument is instead the constraint.
### <a name="3.8.6"/>3.8.6 Type Inference
In certain contexts, inferences for a given set of type parameters are made *from* a type *S*, in which those type parameters do not occur, *to* another type *T*, in which those type parameters do occur. Inferences consist of a set of candidate type arguments collected for each of the type parameters. The inference process recursively relates *S* and *T* to gather as many inferences as possible:
* If *T* is one of the type parameters for which inferences are being made, *S* is added to the set of inferences for that type parameter.
* Otherwise, if *S* and *T* are references to the same generic type, inferences are made from each type argument in *S* to each corresponding type argument in *T*.
* Otherwise, if *T* is a union type:
* First, inferences are made from *S* to each constituent type in *T* that isnt simply one of the type parameters for which inferences are being made.
* If the first step produced no inferences and exactly one constituent type in *T* is simply a type parameter for which inferences are being made, inferences are made from *S* to that type parameter.
* Otherwise, if *S* is a union type, inferences are made from each constituent type in *S* to *T*.
* Otherwise, if *S* and *T* are object types, then for each member *M* in *T*:
* If *M* is a property and *S* contains a property *N* with the same name as *M*, inferences are made from the type of *N* to the type of *M*.
* If *M* is a call signature and a corresponding call signature *N* exists in *S*, *N* is instantiated with the Any type as an argument for each type parameter (if any) and inferences are made from parameter types in *N* to the corresponding parameter types in *M* for positions that are present in both signatures, and from the return type of *N* to the return type of *M*.
@ -1954,29 +2083,12 @@ infers the type of
The following example shows the results of widening types to produce inferred variable types.
```TypeScript
var a = null; // var a: any
var b = undefined; // var b: any
var c = { x: 0, y: null }; // var c: { x: number, y: any }
var d = [ null, undefined ]; // var d: any[]
var a = null; // var a: any
var b = undefined; // var b: any
var c = { x: 0, y: null }; // var c: { x: number, y: any }
var d = [ null, undefined ]; // var d: any[]
```
## <a name="3.10"/>3.10 Best Common Type
In several situations a ***best common type*** needs to be inferred from a set of types. In particular, return types of functions with multiple return statements and element types of array literals are found this way. The determination of a best common type may in some cases factor in a contextual type.
Given a set of types { *T<sub>1</sub>*, *T<sub>2</sub>*, …, *T<sub>n</sub>* } and a contextual type *C*, the best common type is determined as follows:
* If the set of types is empty, the best common type is *C*.
* Otherwise, if C is a supertype of every *T<sub>n</sub>*, the best common type is C.
* Otherwise, if one exists, the first *T<sub>x</sub>* that is a supertype of every *T<sub>n</sub>* is the best common type.
* Otherwise, the best common type is an empty object type (the type `{}`).
Given a set of types { *T<sub>1</sub>*, *T<sub>2</sub>*, …, *T<sub>n</sub>* } and no contextual type, the best common type is determined as follows:
* If the set of types is empty, the best common type is an empty object type.
* Otherwise, if one exists, the first *T<sub>x</sub>* that is a supertype of every *T<sub>n</sub>* is the best common type.
* Otherwise, the best common type is an empty object type (the type `{}`).
<br/>
# <a name="4"/>4 Expressions
@ -2068,7 +2180,7 @@ f : function ( ... ) { ... }
Each property assignment in an object literal is processed as follows:
* If the object literal is contextually typed and the contextual type contains a property with a matching name, the property assignment is contextually typed by the type of that property.
* Otherwise, if the object literal is contextually typed, the contextual type contains a numeric index signature, and the property assignment specifies a numeric property name, the property assignment is contextually typed by the type of the numeric index signature.
* Otherwise, if the object literal is contextually typed, if the contextual type contains a numeric index signature, and if the property assignment specifies a numeric property name, the property assignment is contextually typed by the type of the numeric index signature.
* Otherwise, if the object literal is contextually typed and the contextual type contains a string index signature, the property assignment is contextually typed by the type of the string index signature.
* Otherwise, the property assignment is processed without a contextual type.
@ -2082,14 +2194,14 @@ A get accessor declaration is processed in the same manner as an ordinary functi
If a get accessor is declared for a property, the return type of the get accessor becomes the type of the property. If only a set accessor is declared for a property, the parameter type (which may be type Any if no type annotation is present) of the set accessor becomes the type of the property.
When an object literal is contextually typed by a type that includes a string index signature of type *T*, the resulting type of the object literal includes a string index signature with the widened form of the best common type of the contextual type *T* and the types of the properties declared in the object literal. Likewise, when an object literal is contextually typed by a type that includes a numeric index signature of type *T*, the resulting type of the object literal includes a numeric index signature with the widened form of the best common type of the contextual type *T* and the types of the numerically named properties (section [3.7.4](#3.7.4)) declared in the object literal.
When an object literal is contextually typed by a type that includes a string index signature, the resulting type of the object literal includes a string index signature with the union type of the types of the properties declared in the object literal, or the Undefined type if the object literal is empty. Likewise, when an object literal is contextually typed by a type that includes a numeric index signature, the resulting type of the object literal includes a numeric index signature with the union type of the types of the numerically named properties (section [3.7.4](#3.7.4)) declared in the object literal, or the Undefined type if the object literal declares no numerically named properties.
## <a name="4.6"/>4.6 Array Literals
An array literal
```TypeScript
[expr1, expr2, ..., exprN]
[ expr1, expr2, ..., exprN ]
```
denotes a value of an array type (section [3.3.2](#3.3.2)) or a tuple type (section [3.3.3](#3.3.3)) depending on context.
@ -2100,22 +2212,17 @@ Each element expression in a non-empty array literal is processed as follows:
* Otherwise, if the array literal is contextually typed by a type *T* with a numeric index signature, the element expression is contextually typed by the type of the numeric index signature.
* Otherwise, the element expression is not contextually typed.
The resulting type of a non-empty array literal expression is determined as follows:
The resulting type an array literal expression is determined as follows:
* If the array literal is contextually typed by a type *T* and *T* has at least one property with a numeric name that matches the index of an element expression in the array literal, the resulting type is a tuple type constructed from the types of the element expressions.
* Otherwise, if the array literal is contextually typed by a type T with a numeric index signature of type *S*, the resulting type is an array type where the element type is the best common type of the contextual type *S* and the types of the element expressions.
* Otherwise, if the array literal is not contextually typed, the resulting type is an array type where the element type is the best common type of the types of the element expressions.
The resulting type of an empty array literal expression is determined as follows:
* If the array literal is contextually typed by a type *T* with a numeric index signature of type *S*, the resulting type is an array type with element type *S*.
* Otherwise, the resulting type is an array type with the element type Undefined.
* If the array literal is empty, the resulting type is an array type with the element type Undefined.
* Otherwise, if the array literal is contextually typed by a type that has a property with the numeric name 0, the resulting type is a tuple type constructed from the types of the element expressions.
* Otherwise, the resulting type is an array type with an element type that is the union of the types of the element expressions.
The rules above mean that an array literal is always of an array type, unless it is contextually typed by a type with numerically named properties (such as a tuple type). For example
```TypeScript
var a = [1, 2]; // number[]
var b = ["hello", true]; // {}[]
var a = [1, 2]; // Array<number>
var b = ["hello", true]; // Array<string | boolean>
var c: [number, string] = [3, "three"]; // [number, string]
```
@ -2336,7 +2443,7 @@ var s = data[0]; // string
var n = data[1]; // number
```
## <a name="4.11"/>4.11 The new Operator
## <a name="4.11"/>4.11 The new Operator
A `new` operation has one of the following forms:
@ -2383,8 +2490,7 @@ The compile-time processing of a typed function call consists of the following s
* the function call has no type arguments, and
* the signature is applicable with respect to the argument list of the function call.
* A generic signature is a candidate in a function call without type arguments when
* type inference (section [4.12.2](#4.12.2)) succeeds in inferring a list of type arguments,
* the inferred type arguments satisfy their constraints, and
* type inference (section [4.12.2](#4.12.2)) succeeds for each type parameter,
* once the inferred type arguments are substituted for their associated type parameters, the signature is applicable with respect to the argument list of the function call.
* A generic signature is a candidate in a function call with type arguments when
* The signature has the same number of type parameters as were supplied in the type argument list,
@ -2404,10 +2510,11 @@ A signature is said to be an ***applicable signature*** with respect to an argum
Given a signature &lt; *T<sub>1</sub>* , *T<sub>2</sub>* , … , *T<sub>n</sub>* > ( *p<sub>1</sub>* : *P<sub>1</sub>* , *p<sub>2</sub>* : *P<sub>2</sub>* , … , *p<sub>m</sub>* : *P<sub>m</sub>* ), where each parameter type *P* references zero or more of the type parameters *T*, and an argument list ( *e<sub>1</sub>* , *e<sub>2</sub>* , … , *e<sub>m</sub>* ), the task of type argument inference is to find a set of type arguments *A<sub>1</sub>*…*A<sub>n</sub>* to substitute for *T<sub>1</sub>*…*T<sub>n</sub>* such that the argument list becomes an applicable signature.
The inferred type argument for a particular type parameter is determined from a set of candidate types. Given a type parameter *T*, let *C* denote the widened form (section [3.9](#3.9)) of the best common type (section [3.10](#3.10)) of the set of candidate types *T*. Then,
Type argument inference produces a set of candidate types for each type parameter. Given a type parameter *T* and set of candidate types, the actual inferred type argument is determined as follows:
* If *C* satisfies *T*s constraint, the inferred type argument for *T* is *C*.
* Otherwise, the inferred type argument for *T* is *T*s constraint.
* If the set of candidate argument types is empty, the inferred type argument for *T* is *T*s constraint.
* Otherwise, if at least one of the candidate types is a supertype of all of the other candidate types, let *C* denote the first such candidate type. If *C* satisfies *T*s constraint, the inferred type argument for *T* is *C*. Otherwise, the inferred type argument for *T* is *T*s constraint.
* Otherwise, if no candidate type is a supertype of all of the other candidate types, type inference has fails and no type argument is inferred for *T*.
In order to compute candidate types, the argument list is processed as follows:
@ -2417,27 +2524,27 @@ In order to compute candidate types, the argument list is processed as follows:
The process of inferentially typing an expression *e* by a type *T* is the same as that of contextually typing *e* by *T*, with the following exceptions:
* Where expressions contained within *e* would be contextually typed, they are instead inferentially typed.
* Where a contextual type would be included in a best common type determination (such as when inferentially typing an object or array literal), an inferential type is not.
* When a function expression is inferentially typed (section [4.9.3](#4.9.3)) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, the corresponding inferred type arguments to become ***fixed*** and no further candidate inferences are made for them.
* If *e* is an expression of a function type that contains exactly one generic call signature and no other members, and *T* is a function type with exactly one non-generic call signature and no other members, then any inferences made for type parameters referenced by the parameters of *T*s call signature are ***fixed***, and *e*s type is changed to a function type with *e*s call signature instantiated in the context of *T*s call signature (section [3.8.5](#3.8.5)).
In the example
An example:
```TypeScript
function choose<T>(x: T, y: T): T {
return Math.random() < 0.5 ? x : y;
}
var x = choose("Five", 5);
var x = choose(10, 20); // Ok, x of type number
var y = choose("Five", 5); // Error
```
inferences for T in the call to choose are made as follows: For the first parameter, an inference is made from type string to T. For the second parameter, an inference is made from type number to T. Since the best common type (section [3.10](#3.10)) of string and number is the empty object type, the call to choose is equivalent to
In the first call to choose, two inferences are made from number to T, one for each parameter. Thus, number is inferred for T and the call is equivalent to
```TypeScript
var x = choose<{}>("Five", 5);
var x = choose<number>(10, 20);
```
and the resulting type of x is therefore the empty object type. Note that had both arguments been of type string or number, x would have been of that type.
In the second call to choose, an inference is made from type string to T for the first parameter and an inference is made from type number to T for the second parameter. Since neither string nor number is a supertype of the other, type inference fails. That in turn means there are no applicable signatures and the function call is an error.
In the example
@ -2590,7 +2697,7 @@ The
### <a name="4.14.6"/>4.14.6 The typeof Operator
The typeof operator takes an operand of any type and produces a value of the String primitive type. In positions where a type is expected, typeof can also be used in a type query (section [3.6.8](#3.6.8)) to produce the type of an expression.
The typeof operator takes an operand of any type and produces a value of the String primitive type. In positions where a type is expected, typeof can also be used in a type query (section [3.6.9](#3.6.9)) to produce the type of an expression.
```TypeScript
var x = 5;
@ -2676,9 +2783,9 @@ The && operator permits the operands to be of any type and produces a result of
The || operator permits the operands to be of any type.
If the || expression is contextually typed (section [4.19](#4.19)), the operands are contextually typed by the same type and the result is of the best common type (section [3.10](#3.10)) of the contextual type and the two operand types.
If the || expression is contextually typed (section [4.19](#4.19)), the operands are contextually typed by the same type. Otherwise, the left operand is not contextually typed and the right operand is contextually typed by the type of the left operand.
If the || expression is not contextually typed, the right operand is contextually typed by the type of the left operand and the result is of the best common type of the two operand types.
The type of the result is the union type of the two operand types.
||Any|Boolean|Number|String|Object|
|:---:|:---:|:---:|:---:|:---:|:---:|
@ -2698,9 +2805,9 @@ test ? expr1 : expr2
the *test* expression may be of any type.
If the conditional expression is contextually typed (section [4.19](#4.19)), *expr1* and *expr2* are contextually typed by the same type and the result is of the best common type (section [3.10](#3.10)) of the contextual type and the types of *expr1* and *expr2*. An error occurs if the best common type is not identical to at least one of the three candidate types.
If the conditional expression is contextually typed (section [4.19](#4.19)), *expr1* and *expr2* are contextually typed by the same type. Otherwise, *expr1* and *expr2* are not contextually typed.
If the conditional expression is not contextually typed, the result is of the best common type of the types of *Expr1* and *Expr2*. An error occurs if the best common type is not identical to at least one of the two candidate types.
The type of the result is the union type of the types of *expr1* and *expr2*.
## <a name="4.17"/>4.17 Assignment Operators
@ -2804,6 +2911,112 @@ setEventHandlers({
the object literal passed to setEventHandlers is contextually typed to the EventHandlers type. This causes the two property assignments to be contextually typed to the unnamed function type (event: EventObject) => void, which in turn causes the e parameters in the arrow function expressions to automatically be typed as EventObject.
## <a name="4.20"/>4.20 Type Guards
Type guards are particular expression patterns involving the typeof and instanceof operators that cause the types of variables or parameters to be ***narrowed*** to more specific types. For example, in the code below, knowledge of the static type of x in combination with a typeof check makes it safe to narrow the type of x to string in the first branch of the if statement and number in the second branch of the if statement.
```TypeScript
function foo(x: number | string) {
if (typeof x === "string") {
return x.length; // x has type string here
}
else {
return x + 1; // x has type number here
}
}
```
The type of a variable or parameter is narrowed in the following situations:
* In the true branch statement of an if statement, the type of a variable or parameter is *narrowed* by any type guard in the if condition *when true*, provided the true branch statement contains no assignments to the variable or parameter.
* In the false branch statement of an if statement, the type of a variable or parameter is *narrowed* by any type guard in the if condition *when false*, provided the false branch statement contains no assignments to the variable or parameter.
* In the true expression of a conditional expression, the type of a variable or parameter is *narrowed* by any type guard in the condition *when true*, provided the true expression contains no assignments to the variable or parameter.
* In the false expression of a conditional expression, the type of a variable or parameter is *narrowed* by any type guard in the condition *when false*, provided the false expression contains no assignments to the variable or parameter.
* In the right operand of a && operation, the type of a variable or parameter is *narrowed* by any type guard in the left operand *when true*, provided the right operand contains no assignments to the variable or parameter.
* In the right operand of a || operation, the type of a variable or parameter is *narrowed* by any type guard in the left operand *when false*, provided the right operand contains no assignments to the variable or parameter.
A type guard is simply an expression that follows a particular pattern. The process of narrowing the type of a variable *x* by a type guard *when true* or *when false* depends on the type guard as follows:
* A type guard of the form `x instanceof C`, where *C* is of a subtype of the global type Function and *C* has a property named prototype
* *when true*, narrows the type of *x* to the type of the prototype property in *C* provided it is a subtype of the type of *x*, or
* *when false*, has no effect on the type of *x*.
* A type guard of the form `typeof x === s`, where *s* is a string literal with the value string, number, or boolean,
* *when true*, narrows the type of *x* to the given primitive type, or
* *when false*, removes the primitive type from the type of *x*.
* A type guard of the form `typeof x === s`, where *s* is a string literal with any value but string, number, or boolean,
* *when true*, removes the primitive types string, number, and boolean from the type of *x*, or
* *when false*, has no effect on the type of *x*.
* A type guard of the form `typeof x !== s`, where *s* is a string literal,
* *when true*, narrows the type of x by `typeof x === s` *when false*, or
* *when false*, narrows the type of x by `typeof x === s` *when true*.
* A type guard of the form `!expr`
* *when true*, narrows the type of *x* by *expr* *when false*, or
* *when false*, narrows the type of *x* by *expr* *when true*.
* A type guard of the form `expr1 && expr2`
* *when true*, narrows the type of *x* by *expr<sub>1</sub>* *when true* and then by *expr<sub>2</sub>* *when true*, or
* *when false*, narrows the type of *x* to *T<sub>1</sub>* | *T<sub>2</sub>*, where *T<sub>1</sub>* is the type of *x* narrowed by *expr<sub>1</sub>* *when false*, and *T<sub>2</sub>* is the type of *x* narrowed by *expr<sub>1</sub>* *when true* and then by *expr<sub>2</sub>* *when false*.
* A type guard of the form `expr1 || expr2`
* *when true*, narrows the type of *x* to *T<sub>1</sub>* | *T<sub>2</sub>*, where *T<sub>1</sub>* is the type of *x* narrowed by *expr<sub>1</sub>* *when true*, and *T<sub>2</sub>* is the type of *x* narrowed by *expr<sub>1</sub>* *when false* and then by *expr<sub>2</sub>* *when true*, or
* *when false*, narrows the type of *x* by *expr<sub>1</sub>* *when false* and then by *expr<sub>2</sub>* *when false*.
* A type guard of any other form has no effect on the type of *x*.
A primitive type *P* is removed from a type *T* as follows:
* If *T* is a union type *P* | *T<sub>1</sub>* | *T<sub>2</sub>* | … | *T<sub>n</sub>*, the result is the type *T<sub>1</sub>* | *T<sub>2</sub>* | … | *T<sub>n</sub>*.
* Otherwise, the result is *T*.
Note that type guards affect types of variables and parameters only and have no effect on members of objects such as properties. Also note that it is possible to defeat a type guard by calling a function that changes the type of the guarded variable.
In the example
```TypeScript
function isLongString(obj: any) {
return typeof obj === "string" && obj.length > 100;
}
```
the obj parameter has type string in the right operand of the && operator.
In the example
```TypeScript
function f(x: string | number | boolean) {
if (typeof x === "string" || typeof x === "number") {
var y = x; // Type of y is string | number
}
else {
var z = x; // Type of z is boolean
}
}
```
the type of x is string | number | boolean in left operand of the || operator, number | boolean in the right operand of the || operator, string | number in the first branch of the if statement, and boolean in the second branch of the if statement.
In the example
```TypeScript
function processData(data: string | { (): string }) {
var d = typeof data !== "string" ? data() : data;
// Process string in d
}
```
the inferred type of d is string.
In the example
```TypeScript
class NamedItem {
name: string;
}
function getName(obj: any) {
return obj instanceof NamedItem ? obj.name : "unknown";
}
```
the inferred type of the getName function is string.
<br/>
# <a name="5"/>5 Statements
@ -3000,7 +3213,8 @@ A function implementation without a return type annotation is said to be an ***i
* If there are no return statements with expressions in *f*s function body, the inferred return type is Void.
* Otherwise, if *f*s function body directly references *f* or references any implicitly typed functions that through this same analysis reference *f*, the inferred return type is Any.
* Otherwise, the inferred return type is the widened form (section [3.9](#3.9)) of the best common type (section [3.10](#3.10)) of the types of the return statement expression in the function body, ignoring return statements with no expressions. A compile-time error occurs if the best common type isnt one of the return statement expression types (i.e. if the best common type is an empty type).
* Otherwise, if *f* is a contextually typed function expression (section [4.9.3](#4.9.3)), the inferred return type is the union type (section [3.3.4](#3.3.4)) of the types of the return statement expressions in the function body, ignoring return statements with no expressions.
* Otherwise, the inferred return type is the first of the types of the return statement expressions in the function body that is a supertype (section [3.8.3](#3.8.3)) of each of the others, ignoring return statements with no expressions. A compile-time error occurs if no return statement expression has a type that is a supertype of each of the others.
In the example
@ -4961,6 +5175,7 @@ This appendix contains a summary of the grammar found in the main document. As d
&emsp;&emsp;&emsp;*ObjectType*
&emsp;&emsp;&emsp;*ArrayType*
&emsp;&emsp;&emsp;*TupleType*
&emsp;&emsp;&emsp;*UnionType*
&emsp;&emsp;&emsp;*FunctionType*
&emsp;&emsp;&emsp;*ConstructorType*
&emsp;&emsp;&emsp;*TypeQuery*
@ -5021,6 +5236,13 @@ This appendix contains a summary of the grammar found in the main document. As d
&emsp;&emsp;*TupleElementType:*
&emsp;&emsp;&emsp;*Type*
&emsp;&emsp;*UnionType:*
&emsp;&emsp;&emsp;*ElementType*&emsp;`|`&emsp;*UnionOrElementType*
&emsp;&emsp;*UnionOrElementType:*
&emsp;&emsp;&emsp;*UnionType*
&emsp;&emsp;&emsp;*ElementType*
&emsp;&emsp;*FunctionType:*
&emsp;&emsp;&emsp;*TypeParameters<sub>opt</sub>*&emsp;`(`&emsp;*ParameterList<sub>opt</sub>*&emsp;`)`&emsp;`=>`&emsp;*Type*

File diff suppressed because it is too large Load Diff

View File

@ -82,7 +82,7 @@ module ts {
return array1.concat(array2);
}
export function uniqueElements<T>(array: T[]): T[] {
export function deduplicate<T>(array: T[]): T[] {
if (array) {
var result: T[] = [];
for (var i = 0, len = array.length; i < len; i++) {

View File

@ -188,8 +188,6 @@ module ts {
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: { code: 2363, category: DiagnosticCategory.Error, key: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." },
Invalid_left_hand_side_of_assignment_expression: { code: 2364, category: DiagnosticCategory.Error, key: "Invalid left-hand side of assignment expression." },
Operator_0_cannot_be_applied_to_types_1_and_2: { code: 2365, category: DiagnosticCategory.Error, key: "Operator '{0}' cannot be applied to types '{1}' and '{2}'." },
No_best_common_type_exists_between_0_1_and_2: { code: 2366, category: DiagnosticCategory.Error, key: "No best common type exists between '{0}', '{1}', and '{2}'." },
No_best_common_type_exists_between_0_and_1: { code: 2367, category: DiagnosticCategory.Error, key: "No best common type exists between '{0}' and '{1}'." },
Type_parameter_name_cannot_be_0: { code: 2368, category: DiagnosticCategory.Error, key: "Type parameter name cannot be '{0}'" },
A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2369, category: DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." },
A_rest_parameter_must_be_of_an_array_type: { code: 2370, category: DiagnosticCategory.Error, key: "A rest parameter must be of an array type." },

View File

@ -744,14 +744,6 @@
"category": "Error",
"code": 2365
},
"No best common type exists between '{0}', '{1}', and '{2}'.": {
"category": "Error",
"code": 2366
},
"No best common type exists between '{0}' and '{1}'.": {
"category": "Error",
"code": 2367
},
"Type parameter name cannot be '{0}'": {
"category": "Error",
"code": 2368

View File

@ -4,8 +4,11 @@
/// <reference path="parser.ts"/>
module ts {
interface EmitTextWriter extends SymbolWriter {
interface EmitTextWriter {
write(s: string): void;
writeLine(): void;
increaseIndent(): void;
decreaseIndent(): void;
getText(): string;
rawWrite(s: string): void;
writeLiteral(s: string): void;
@ -15,6 +18,9 @@ module ts {
getIndent(): number;
}
interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter{
}
var indentStrings: string[] = ["", " "];
export function getIndentString(level: number) {
if (indentStrings[level] === undefined) {
@ -103,7 +109,7 @@ module ts {
};
}
function createTextWriter(trackSymbol: (symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags)=> void): EmitTextWriter {
function createTextWriter(): EmitTextWriter {
var output = "";
var indent = 0;
var lineStart = true;
@ -149,17 +155,8 @@ module ts {
}
}
function writeKind(text: string, kind: SymbolDisplayPartKind) {
write(text);
}
function writeSymbol(text: string, symbol: Symbol) {
write(text);
}
return {
write: write,
trackSymbol: trackSymbol,
writeKind: writeKind,
writeSymbol: writeSymbol,
rawWrite: rawWrite,
writeLiteral: writeLiteral,
writeLine: writeLine,
@ -170,7 +167,6 @@ module ts {
getLine: () => lineCount + 1,
getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1,
getText: () => output,
clear: () => { }
};
}
@ -318,7 +314,7 @@ module ts {
}
function emitJavaScript(jsFilePath: string, root?: SourceFile) {
var writer = createTextWriter(trackSymbol);
var writer = createTextWriter();
var write = writer.write;
var writeLine = writer.writeLine;
var increaseIndent = writer.increaseIndent;
@ -374,8 +370,6 @@ module ts {
/** Sourcemap data that will get encoded */
var sourceMapData: SourceMapData;
function trackSymbol(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags) { }
function initializeEmitterWithSourceMaps() {
var sourceMapDir: string; // The directory in which sourcemap will be
@ -2337,7 +2331,7 @@ module ts {
}
function emitDeclarations(jsFilePath: string, root?: SourceFile) {
var writer = createTextWriter(trackSymbol);
var writer = createTextWriterWithSymbolWriter();
var write = writer.write;
var writeLine = writer.writeLine;
var increaseIndent = writer.increaseIndent;
@ -2361,11 +2355,24 @@ module ts {
typeName?: Identifier
}
function createTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter {
var writer = <EmitTextWriterWithSymbolWriter>createTextWriter();
writer.trackSymbol = trackSymbol;
writer.writeKeyword = writer.write;
writer.writeOperator = writer.write;
writer.writePunctuation = writer.write;
writer.writeSpace = writer.write;
writer.writeStringLiteral = writer.writeLiteral;
writer.writeParameter = writer.write;
writer.writeSymbol = writer.write;
return writer;
}
function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) {
var oldWriter = writer;
forEach(importDeclarations, aliasToWrite => {
var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined);
writer = createTextWriter(trackSymbol);
writer = createTextWriterWithSymbolWriter();
for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
writer.increaseIndent();
}

View File

@ -225,6 +225,8 @@ module ts {
return child((<ArrayTypeNode>node).elementType);
case SyntaxKind.TupleType:
return children((<TupleTypeNode>node).elementTypes);
case SyntaxKind.UnionType:
return children((<UnionTypeNode>node).types);
case SyntaxKind.ArrayLiteral:
return children((<ArrayLiteral>node).elements);
case SyntaxKind.ObjectLiteral:
@ -1729,9 +1731,9 @@ module ts {
}
}
function parseType(): TypeNode {
function parseNonUnionType(): TypeNode {
var type = parseNonArrayType();
while (type && !scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) {
while (!scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.OpenBracketToken)) {
parseExpected(SyntaxKind.CloseBracketToken);
var node = <ArrayTypeNode>createNode(SyntaxKind.ArrayType, type.pos);
node.elementType = type;
@ -1740,6 +1742,22 @@ module ts {
return type;
}
function parseType(): TypeNode {
var type = parseNonUnionType();
if (token === SyntaxKind.BarToken) {
var types = <NodeArray<TypeNode>>[type];
types.pos = type.pos;
while (parseOptional(SyntaxKind.BarToken)) {
types.push(parseNonUnionType());
}
types.end = getNodeEnd();
var node = <UnionTypeNode>createNode(SyntaxKind.UnionType, type.pos);
node.types = types;
type = finishNode(node);
}
return type;
}
function parseTypeAnnotation(): TypeNode {
return parseOptional(SyntaxKind.ColonToken) ? parseType() : undefined;
}

View File

@ -154,6 +154,7 @@ module ts {
TypeLiteral,
ArrayType,
TupleType,
UnionType,
// Expression
ArrayLiteral,
ObjectLiteral,
@ -224,7 +225,7 @@ module ts {
FirstFutureReservedWord = ImplementsKeyword,
LastFutureReservedWord = YieldKeyword,
FirstTypeNode = TypeReference,
LastTypeNode = TupleType,
LastTypeNode = UnionType,
FirstPunctuation = OpenBraceToken,
LastPunctuation = CaretEqualsToken,
FirstToken = EndOfFileToken,
@ -340,6 +341,10 @@ module ts {
elementTypes: NodeArray<TypeNode>;
}
export interface UnionTypeNode extends TypeNode {
types: NodeArray<TypeNode>;
}
export interface StringLiteralTypeNode extends TypeNode {
text: string;
}
@ -651,7 +656,7 @@ module ts {
writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void;
getFullyQualifiedName(symbol: Symbol): string;
getAugmentedPropertiesOfApparentType(type: Type): Symbol[];
getRootSymbol(symbol: Symbol): Symbol;
getRootSymbols(symbol: Symbol): Symbol[];
getContextualType(node: Node): Type;
getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature;
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
@ -659,6 +664,8 @@ module ts {
writeTypeParameter(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void;
writeTypeParametersOfSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags): void;
isImplementationOfOverload(node: FunctionDeclaration): boolean;
isUndefinedSymbol(symbol: Symbol): boolean;
isArgumentsSymbol(symbol: Symbol): boolean;
// Returns the constant value of this enum member, or 'undefined' if the enum member has a
// computed value.
@ -669,7 +676,12 @@ module ts {
}
export interface SymbolWriter {
writeKind(text: string, kind: SymbolDisplayPartKind): void;
writeKeyword(text: string): void;
writeOperator(text: string): void;
writePunctuation(text: string): void;
writeSpace(text: string): void;
writeStringLiteral(text: string): void;
writeParameter(text: string): void;
writeSymbol(text: string, symbol: Symbol): void;
writeLine(): void;
increaseIndent(): void;
@ -698,6 +710,9 @@ module ts {
// eg. class C<T> { p: T } <-- Show p as C<T>.p here
// var a: C<number>;
// var p = a.p; <--- Here p is property of C<number> so show it as C<number>.p instead of just C.p
UseOnlyExternalAliasing = 0x00000002, // Use only external alias information to get the symbol name in the given context
// eg. module m { export class c { } } import x = m.c;
// When this flag is specified m.c will be used to refer to the class instead of alias symbol x
}
export enum SymbolAccessibility {
@ -755,23 +770,22 @@ module ts {
ConstructSignature = 0x00010000, // Construct signature
IndexSignature = 0x00020000, // Index signature
TypeParameter = 0x00040000, // Type parameter
UnionProperty = 0x00080000, // Property in union type
// Export markers (see comment in declareModuleMember in binder)
ExportValue = 0x00080000, // Exported value marker
ExportType = 0x00100000, // Exported type marker
ExportNamespace = 0x00200000, // Exported namespace marker
ExportValue = 0x00100000, // Exported value marker
ExportType = 0x00200000, // Exported type marker
ExportNamespace = 0x00400000, // Exported namespace marker
Import = 0x00400000, // Import
Instantiated = 0x00800000, // Instantiated symbol
Merged = 0x01000000, // Merged symbol (created during program binding)
Transient = 0x02000000, // Transient symbol (created during type check)
Prototype = 0x04000000, // Symbol for the prototype property (without source code representation)
Undefined = 0x08000000, // Symbol for the undefined
Import = 0x00800000, // Import
Instantiated = 0x01000000, // Instantiated symbol
Merged = 0x02000000, // Merged symbol (created during program binding)
Transient = 0x04000000, // Transient symbol (created during type check)
Prototype = 0x08000000, // Prototype property (no source representation)
BlockScoped = 0x10000000,
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor,
Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor | UnionProperty,
Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter,
Namespace = ValueModule | NamespaceModule,
Module = ValueModule | NamespaceModule,
@ -830,6 +844,7 @@ module ts {
mapper?: TypeMapper; // Type mapper for instantiation alias
referenced?: boolean; // True if alias symbol has been referenced as a value
exportAssignSymbol?: Symbol; // Symbol exported from external module
unionType?: UnionType; // Containing union type for union property
}
export interface TransientSymbol extends Symbol, SymbolLinks { }
@ -852,14 +867,15 @@ module ts {
}
export interface NodeLinks {
resolvedType?: Type; // Cached type of type node
resolvedSignature?: Signature; // Cached signature of signature node or call expression
resolvedSymbol?: Symbol; // Cached name resolution result
flags?: NodeCheckFlags; // Set of flags specific to Node
enumMemberValue?: number; // Constant value of enum member
resolvedType?: Type; // Cached type of type node
resolvedSignature?: Signature; // Cached signature of signature node or call expression
resolvedSymbol?: Symbol; // Cached name resolution result
flags?: NodeCheckFlags; // Set of flags specific to Node
enumMemberValue?: number; // Constant value of enum member
isIllegalTypeReferenceInConstraint?: boolean; // Is type reference in constraint refers to the type parameter from the same list
isVisible?: boolean; // Is this node visible
localModuleName?: string; // Local name for module instance
isVisible?: boolean; // Is this node visible
localModuleName?: string; // Local name for module instance
assignmentChecks?: Map<boolean>; // Cache of assignment checks
}
export enum TypeFlags {
@ -877,13 +893,14 @@ module ts {
Interface = 0x00000800, // Interface
Reference = 0x00001000, // Generic type reference
Tuple = 0x00002000, // Tuple
Anonymous = 0x00004000, // Anonymous
FromSignature = 0x00008000, // Created for signature assignment check
Union = 0x00004000, // Union
Anonymous = 0x00008000, // Anonymous
FromSignature = 0x00010000, // Created for signature assignment check
Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null,
Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null,
StringLike = String | StringLiteral,
NumberLike = Number | Enum,
ObjectType = Class | Interface | Reference | Tuple | Anonymous
ObjectType = Class | Interface | Reference | Tuple | Union | Anonymous,
}
// Properties common to all types
@ -941,6 +958,10 @@ module ts {
baseArrayType: TypeReference; // Array<T> where T is best common type of element types
}
export interface UnionType extends ObjectType {
types: Type[]; // Constituent types
}
// Resolved object type
export interface ResolvedObjectType extends ObjectType {
members: SymbolTable; // Properties by name
@ -973,6 +994,7 @@ module ts {
hasStringLiterals: boolean; // True if specialized
target?: Signature; // Instantiation target
mapper?: TypeMapper; // Instantiation mapper
unionSignatures?: Signature[]; // Underlying signatures of a union signature
erasedSignatureCache?: Signature; // Erased version of signature (deferred)
isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison
}
@ -987,9 +1009,10 @@ module ts {
}
export interface InferenceContext {
typeParameters: TypeParameter[];
inferences: Type[][];
inferredTypes: Type[];
typeParameters: TypeParameter[]; // Type parameters for which inferences are made
inferenceCount: number; // Incremented for every inference made (whether new or not)
inferences: Type[][]; // Inferences made for each type parameter
inferredTypes: Type[]; // Inferred type for each type parameter
}
export interface DiagnosticMessage {
@ -1220,32 +1243,7 @@ module ts {
tab = 0x09, // \t
verticalTab = 0x0B, // \v
}
export enum SymbolDisplayPartKind {
aliasName,
className,
enumName,
fieldName,
interfaceName,
keyword,
lineBreak,
numericLiteral,
stringLiteral,
localName,
methodName,
moduleName,
operator,
parameterName,
propertyName,
punctuation,
space,
text,
typeParameterName,
enumMemberName,
functionName,
regularExpressionLiteral,
}
export interface CancellationToken {
isCancellationRequested(): boolean;
}

View File

@ -146,7 +146,7 @@ module FourSlash {
function convertGlobalOptionsToCompilationSettings(globalOptions: { [idx: string]: string }): ts.CompilationSettings {
var settings: ts.CompilationSettings = {};
// Convert all property in globalOptions into ts.CompilationSettings
// Convert all property in globalOptions into ts.CompilationSettings
for (var prop in globalOptions) {
if (globalOptions.hasOwnProperty(prop)) {
switch (prop) {
@ -1610,7 +1610,7 @@ module FourSlash {
Harness.IO.log(this.getNameOrDottedNameSpan(pos));
}
private verifyClassifications(expected: { classificationType: string; text: string }[], actual: ts.ClassifiedSpan[]) {
private verifyClassifications(expected: { classificationType: string; text: string; textSpan?: TextSpan }[], actual: ts.ClassifiedSpan[]) {
if (actual.length !== expected.length) {
this.raiseError('verifyClassifications failed - expected total classifications to be ' + expected.length + ', but was ' + actual.length);
}
@ -1626,7 +1626,19 @@ module FourSlash {
actualClassification.classificationType);
}
var expectedSpan = expectedClassification.textSpan;
var actualSpan = actualClassification.textSpan;
if (expectedSpan) {
var expectedLength = expectedSpan.end - expectedSpan.start;
if (expectedSpan.start !== actualSpan.start() || expectedLength !== actualSpan.length()) {
this.raiseError("verifyClassifications failed - expected span of text to be " +
"{start=" + expectedSpan.start + ", length=" + expectedLength + "}, but was " +
"{start=" + actualSpan.start() + ", length=" + actualSpan.length() + "}");
}
}
var actualText = this.activeFile.content.substr(actualSpan.start(), actualSpan.length());
if (expectedClassification.text !== actualText) {
this.raiseError('verifyClassifications failed - expected classificatied text to be ' +

View File

@ -476,8 +476,6 @@ module TypeScript {
//}
}
var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl);
var funcSignature = funcPullDecl.getSignatureSymbol(this.semanticInfoChain);
this.emitDeclarationComments(funcDecl);
this.emitIndent();
@ -603,11 +601,6 @@ module TypeScript {
private emitConstructSignature(funcDecl: ConstructSignatureSyntax) {
var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl);
var start = new Date().getTime();
var funcSymbol = this.semanticInfoChain.getSymbolForAST(funcDecl);
TypeScript.declarationEmitFunctionDeclarationGetSymbolTime += new Date().getTime() - start;
this.emitDeclarationComments(funcDecl);
this.emitIndent();
@ -633,11 +626,6 @@ module TypeScript {
private emitMethodSignature(funcDecl: MethodSignatureSyntax) {
var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl);
var start = new Date().getTime();
var funcSymbol = this.semanticInfoChain.getSymbolForAST(funcDecl);
TypeScript.declarationEmitFunctionDeclarationGetSymbolTime += new Date().getTime() - start;
this.emitDeclarationComments(funcDecl);
this.emitIndent();
@ -817,7 +805,6 @@ module TypeScript {
var parameter = funcDecl.callSignature.parameterList.parameters[i];
var parameterDecl = this.semanticInfoChain.getDeclForAST(parameter);
if (hasFlag(parameterDecl.flags, PullElementFlags.PropertyParameter)) {
var funcPullDecl = this.semanticInfoChain.getDeclForAST(funcDecl);
this.emitDeclarationComments(parameter);
this.declFile.Write(this.getIndentString());
this.emitClassElementModifiers(parameter.modifiers);
@ -838,7 +825,6 @@ module TypeScript {
var className = classDecl.identifier.text();
this.emitDeclarationComments(classDecl);
var classPullDecl = this.semanticInfoChain.getDeclForAST(classDecl);
this.emitDeclFlags(classDecl, "class");
this.declFile.Write(className);
@ -934,7 +920,6 @@ module TypeScript {
var interfaceName = interfaceDecl.identifier.text();
this.emitDeclarationComments(interfaceDecl);
var interfacePullDecl = this.semanticInfoChain.getDeclForAST(interfaceDecl);
this.emitDeclFlags(interfaceDecl, "interface");
this.declFile.Write(interfaceName);
@ -980,7 +965,6 @@ module TypeScript {
}
this.emitDeclarationComments(moduleDecl);
var modulePullDecl = this.semanticInfoChain.getDeclForAST(moduleDecl);
this.emitDeclFlags(moduleDecl, "enum");
this.declFile.WriteLine(moduleDecl.identifier.text() + " {");

View File

@ -512,7 +512,7 @@ module TypeScript {
for (var i = 0, n = fileNames.length; i < n; i++) {
var fileName = fileNames[i];
var document = this.getDocument(fileNames[i]);
var document = this.getDocument(fileName);
sharedEmitter = this._emitDocumentDeclarations(document, emitOptions,
file => emitOutput.outputFiles.push(file), sharedEmitter);
@ -578,7 +578,6 @@ module TypeScript {
var sourceUnit = document.sourceUnit();
Debug.assert(this._shouldEmit(document));
var typeScriptFileName = document.fileName;
if (!emitter) {
var javaScriptFileName = this.mapOutputFileName(document, emitOptions, TypeScriptCompiler.mapToJSFileName);
var outFile = new TextWriter(javaScriptFileName, this.writeByteOrderMarkForDocument(document), OutputFileType.JavaScript);
@ -799,8 +798,6 @@ module TypeScript {
}
private extractResolutionContextFromAST(resolver: PullTypeResolver, ast: ISyntaxElement, document: Document, propagateContextualTypes: boolean): { ast: ISyntaxElement; enclosingDecl: PullDecl; resolutionContext: PullTypeResolutionContext; inContextuallyTypedAssignment: boolean; inWithBlock: boolean; } {
var scriptName = document.fileName;
var enclosingDecl: PullDecl = null;
var enclosingDeclAST: ISyntaxElement = null;
var inContextuallyTypedAssignment = false;
@ -981,7 +978,6 @@ module TypeScript {
case SyntaxKind.ReturnStatement:
if (propagateContextualTypes) {
var returnStatement = <ReturnStatementSyntax>current;
var contextualType: PullTypeSymbol = null;
if (enclosingDecl && (enclosingDecl.kind & PullElementKind.SomeFunction)) {

View File

@ -7,12 +7,6 @@ module TypeScript {
}
export function integerMultiplyLow32Bits(n1: number, n2: number): number {
var n1Low16 = n1 & 0x0000ffff;
var n1High16 = n1 >>> 16;
var n2Low16 = n2 & 0x0000ffff;
var n2High16 = n2 >>> 16;
var resultLow32 = (((n1 & 0xffff0000) * n2) >>> 0) + (((n1 & 0x0000ffff) * n2) >>> 0) >>> 0;
return resultLow32;
}

View File

@ -994,12 +994,37 @@ module ts {
containerKind: string;
containerName: string;
}
export enum SymbolDisplayPartKind {
aliasName,
className,
enumName,
fieldName,
interfaceName,
keyword,
lineBreak,
numericLiteral,
stringLiteral,
localName,
methodName,
moduleName,
operator,
parameterName,
propertyName,
punctuation,
space,
text,
typeParameterName,
enumMemberName,
functionName,
regularExpressionLiteral,
}
export interface SymbolDisplayPart {
text: string;
kind: string;
}
export interface QuickInfo {
kind: string;
kindModifiers: string;
@ -1306,7 +1331,12 @@ module ts {
resetWriter();
return {
displayParts: () => displayParts,
writeKind: writeKind,
writeKeyword: text => writeKind(text, SymbolDisplayPartKind.keyword),
writeOperator: text => writeKind(text, SymbolDisplayPartKind.operator),
writePunctuation: text => writeKind(text, SymbolDisplayPartKind.punctuation),
writeSpace: text => writeKind(text, SymbolDisplayPartKind.space),
writeStringLiteral: text => writeKind(text, SymbolDisplayPartKind.stringLiteral),
writeParameter: text => writeKind(text, SymbolDisplayPartKind.parameterName),
writeSymbol: writeSymbol,
writeLine: writeLine,
increaseIndent: () => { indent++; },
@ -2250,7 +2280,7 @@ module ts {
return undefined;
}
function createCompletionEntry(symbol: Symbol): CompletionEntry {
function createCompletionEntry(symbol: Symbol, typeChecker: TypeChecker): CompletionEntry {
// Try to get a valid display name for this symbol, if we could not find one, then ignore it.
// We would like to only show things that can be added after a dot, so for instance numeric properties can
// not be accessed with a dot (a.1 <- invalid)
@ -2259,9 +2289,13 @@ module ts {
return undefined;
}
// TODO(drosen): Right now we just permit *all* semantic meanings when calling 'getSymbolKind'
// which is permissible given that it is backwards compatible; but really we should consider
// passing the meaning for the node so that we don't report that a suggestion for a value is an interface.
// We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration.
return {
name: displayName,
kind: getSymbolKind(symbol),
kind: getSymbolKind(symbol, typeChecker),
kindModifiers: getSymbolModifiers(symbol)
};
}
@ -2269,7 +2303,7 @@ module ts {
function getCompletionsAtPosition(filename: string, position: number, isMemberCompletion: boolean) {
function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void {
forEach(symbols, symbol => {
var entry = createCompletionEntry(symbol);
var entry = createCompletionEntry(symbol, session.typeChecker);
if (entry && !lookUp(session.symbols, entry.name)) {
session.entries.push(entry);
session.symbols[entry.name] = symbol;
@ -2608,12 +2642,12 @@ module ts {
if (symbol) {
var type = session.typeChecker.getTypeOfSymbol(symbol);
Debug.assert(type, "Could not find type for symbol");
var completionEntry = createCompletionEntry(symbol);
var completionEntry = createCompletionEntry(symbol, session.typeChecker);
// TODO(drosen): Right now we just permit *all* semantic meanings when calling 'getSymbolKind'
// which is permissible given that it is backwards compatible; but really we should consider
// passing the meaning for the node so that we don't report that a suggestion for a value is an interface.
// We COULD also just do what 'getSymbolModifiers' does, which is to use the first declaration.
var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getSourceFile(filename), session.location, session.typeChecker, session.location);
var displayPartsDocumentationsAndSymbolKind = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getSourceFile(filename), session.location, session.typeChecker, session.location, SemanticMeaning.All);
return {
name: entryName,
kind: displayPartsDocumentationsAndSymbolKind.symbolKind,
@ -2657,15 +2691,15 @@ module ts {
}
// TODO(drosen): use contextual SemanticMeaning.
function getSymbolKind(symbol: Symbol): string {
var flags = typeInfoResolver.getRootSymbol(symbol).getFlags();
function getSymbolKind(symbol: Symbol, typeResolver: TypeChecker): string {
var flags = typeInfoResolver.getRootSymbols(symbol)[0].getFlags();
if (flags & SymbolFlags.Class) return ScriptElementKind.classElement;
if (flags & SymbolFlags.Enum) return ScriptElementKind.enumElement;
if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement;
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags);
var result = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, flags, typeResolver);
if (result === ScriptElementKind.unknown) {
if (flags & SymbolFlags.TypeParameter) return ScriptElementKind.typeParameterElement;
if (flags & SymbolFlags.EnumMember) return ScriptElementKind.variableElement;
@ -2675,16 +2709,19 @@ module ts {
return result;
}
function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol: Symbol, flags: SymbolFlags) {
function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol: Symbol, flags: SymbolFlags, typeResolver: TypeChecker) {
if (typeResolver.isUndefinedSymbol(symbol)) {
return ScriptElementKind.variableElement;
}
if (typeResolver.isArgumentsSymbol(symbol)) {
return ScriptElementKind.localVariableElement;
}
if (flags & SymbolFlags.Variable) {
if (isFirstDeclarationOfSymbolParameter(symbol)) {
return ScriptElementKind.parameterElement;
}
return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement;
}
if (flags & SymbolFlags.Undefined) {
return ScriptElementKind.variableElement;
}
if (flags & SymbolFlags.Function) return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localFunctionElement : ScriptElementKind.functionElement;
if (flags & SymbolFlags.GetAccessor) return ScriptElementKind.memberGetAccessorElement;
if (flags & SymbolFlags.SetAccessor) return ScriptElementKind.memberSetAccessorElement;
@ -2737,27 +2774,21 @@ module ts {
: ScriptElementKindModifier.none;
}
// TODO(drosen): use contextual SemanticMeaning.
function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol: Symbol,
sourceFile: SourceFile,
enclosingDeclaration: Node,
typeResolver: TypeChecker,
location: Node) {
function getSymbolDisplayPartsDocumentationAndSymbolKind(symbol: Symbol, sourceFile: SourceFile, enclosingDeclaration: Node,
typeResolver: TypeChecker, location: Node,
// TODO(drosen): Currently completion entry details passes the SemanticMeaning.All instead of using semanticMeaning of location
semanticMeaning = getMeaningFromLocation(location)) {
var displayParts: SymbolDisplayPart[] = [];
var documentation: SymbolDisplayPart[];
var symbolFlags = typeResolver.getRootSymbol(symbol).flags;
var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags);
var symbolFlags = typeResolver.getRootSymbols(symbol)[0].flags;
var symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(symbol, symbolFlags, typeResolver);
var hasAddedSymbolInfo: boolean;
// Class at constructor site need to be shown as constructor apart from property,method, vars
if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Signature || symbolFlags & SymbolFlags.Class) {
if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Class || symbolFlags & SymbolFlags.Import) {
// If it is accessor they are allowed only if location is at name of the accessor
if (symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement) {
symbolKind = ScriptElementKind.memberVariableElement;
}
else if (symbol.name === "undefined") {
// undefined is symbol and not property
symbolKind = ScriptElementKind.variableElement;
}
var type = typeResolver.getTypeOfSymbol(symbol);
if (type) {
@ -2790,6 +2821,18 @@ module ts {
symbolKind = ScriptElementKind.constructorImplementationElement;
addPrefixForAnyFunctionOrVar(type.symbol, symbolKind);
}
else if (symbolFlags & SymbolFlags.Import) {
symbolKind = ScriptElementKind.alias;
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
displayParts.push(textPart(symbolKind));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
displayParts.push(spacePart());
if (useConstructSignatures) {
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
displayParts.push(spacePart());
}
addFullSymbolName(symbol);
}
else {
addPrefixForAnyFunctionOrVar(symbol, symbolKind);
}
@ -2847,45 +2890,44 @@ module ts {
}
}
}
if (symbolFlags & SymbolFlags.Class && !hasAddedSymbolInfo) {
displayParts.push(keywordPart(SyntaxKind.ClassKeyword));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
addFullSymbolName(symbol);
writeTypeParametersOfSymbol(symbol, sourceFile);
}
if (symbolFlags & SymbolFlags.Interface) {
if ((symbolFlags & SymbolFlags.Interface) && (semanticMeaning & SemanticMeaning.Type)) {
addNewLineIfDisplayPartsExist();
displayParts.push(keywordPart(SyntaxKind.InterfaceKeyword));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
addFullSymbolName(symbol);
writeTypeParametersOfSymbol(symbol, sourceFile);
}
if (symbolFlags & SymbolFlags.Enum) {
addNewLineIfDisplayPartsExist();
displayParts.push(keywordPart(SyntaxKind.EnumKeyword));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile));
addFullSymbolName(symbol);
}
if (symbolFlags & SymbolFlags.Module) {
addNewLineIfDisplayPartsExist();
displayParts.push(keywordPart(SyntaxKind.ModuleKeyword));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile));
addFullSymbolName(symbol);
}
if (symbolFlags & SymbolFlags.TypeParameter) {
if ((symbolFlags & SymbolFlags.TypeParameter) && (semanticMeaning & SemanticMeaning.Type)) {
addNewLineIfDisplayPartsExist();
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
displayParts.push(textPart("type parameter"));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration));
addFullSymbolName(symbol);
displayParts.push(spacePart());
displayParts.push(keywordPart(SyntaxKind.InKeyword));
displayParts.push(spacePart());
if (symbol.parent) {
// Class/Interface type parameter
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol.parent, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments))
addFullSymbolName(symbol.parent, enclosingDeclaration);
writeTypeParametersOfSymbol(symbol.parent, enclosingDeclaration);
}
else {
@ -2897,7 +2939,7 @@ module ts {
displayParts.push(spacePart());
}
else if (signatureDeclaration.kind !== SyntaxKind.CallSignature && signatureDeclaration.name) {
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, signatureDeclaration.symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments))
addFullSymbolName(signatureDeclaration.symbol);
}
displayParts.push.apply(displayParts, signatureToDisplayParts(typeResolver, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature));
}
@ -2917,18 +2959,37 @@ module ts {
}
if (symbolFlags & SymbolFlags.Import) {
addNewLineIfDisplayPartsExist();
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
displayParts.push(textPart("alias"));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
displayParts.push(spacePart());
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile));
addFullSymbolName(symbol);
displayParts.push(spacePart());
displayParts.push(punctuationPart(SyntaxKind.EqualsToken));
displayParts.push(spacePart());
ts.forEach(symbol.declarations, declaration => {
if (declaration.kind === SyntaxKind.ImportDeclaration) {
var importDeclaration = <ImportDeclaration>declaration;
if (importDeclaration.externalModuleName) {
displayParts.push(keywordPart(SyntaxKind.RequireKeyword));
displayParts.push(punctuationPart(SyntaxKind.OpenParenToken));
displayParts.push(displayPart(getTextOfNode(importDeclaration.externalModuleName), SymbolDisplayPartKind.stringLiteral));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
}
else {
var internalAliasSymbol = typeResolver.getSymbolInfo(importDeclaration.entityName);
addFullSymbolName(internalAliasSymbol, enclosingDeclaration);
}
return true;
}
});
}
if (!hasAddedSymbolInfo) {
if (symbolKind !== ScriptElementKind.unknown) {
if (type) {
addPrefixForAnyFunctionOrVar(symbol, symbolKind);
// For properties, variables and local vars: show the type
if (symbolKind === ScriptElementKind.memberVariableElement ||
symbolFlags & SymbolFlags.Variable) {
symbolFlags & SymbolFlags.Variable ||
symbolKind === ScriptElementKind.localVariableElement) {
displayParts.push(punctuationPart(SyntaxKind.ColonToken));
displayParts.push(spacePart());
// If the type is type parameter, format it specially
@ -2953,7 +3014,7 @@ module ts {
}
}
else {
symbolKind = getSymbolKind(symbol);
symbolKind = getSymbolKind(symbol, typeResolver);
}
}
@ -2969,6 +3030,12 @@ module ts {
}
}
function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) {
var fullSymbolDisplayParts = symbolToDisplayParts(typeResolver, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined,
SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing);
displayParts.push.apply(displayParts, fullSymbolDisplayParts);
}
function addPrefixForAnyFunctionOrVar(symbol: Symbol, symbolKind: string) {
addNewLineIfDisplayPartsExist();
if (symbolKind) {
@ -2976,8 +3043,7 @@ module ts {
displayParts.push(textPart(symbolKind));
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
displayParts.push(spacePart());
// Write type parameters of class/Interface if it is property/method of the generic class/interface
displayParts.push.apply(displayParts, symbolToDisplayParts(typeResolver, symbol, sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
addFullSymbolName(symbol);
}
}
@ -3015,7 +3081,6 @@ module ts {
var symbol = typeInfoResolver.getSymbolInfo(node);
if (!symbol) {
// Try getting just type at this position and show
switch (node.kind) {
case SyntaxKind.Identifier:
@ -3023,7 +3088,7 @@ module ts {
case SyntaxKind.QualifiedName:
case SyntaxKind.ThisKeyword:
case SyntaxKind.SuperKeyword:
// For the identifiers/this/usper etc get the type at position
// For the identifiers/this/super etc get the type at position
var type = typeInfoResolver.getTypeOfNode(node);
if (type) {
return {
@ -3050,7 +3115,7 @@ module ts {
}
/// Goto definition
function getDefinitionAtPosition(filename: string, position: number): DefinitionInfo[]{
function getDefinitionAtPosition(filename: string, position: number): DefinitionInfo[] {
function getDefinitionInfo(node: Node, symbolKind: string, symbolName: string, containerName: string): DefinitionInfo {
return {
fileName: node.getSourceFile().filename,
@ -3082,7 +3147,7 @@ module ts {
result.push(getDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName));
return true;
}
return false;
}
@ -3146,7 +3211,7 @@ module ts {
// Could not find a symbol e.g. node is string or number keyword,
// or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
if (!symbol || !(symbol.getDeclarations())) {
if (!symbol) {
return undefined;
}
@ -3154,7 +3219,7 @@ module ts {
var declarations = symbol.getDeclarations();
var symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol
var symbolKind = getSymbolKind(symbol);
var symbolKind = getSymbolKind(symbol, typeInfoResolver);
var containerSymbol = symbol.parent;
var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : "";
@ -3679,18 +3744,20 @@ module ts {
return [getReferenceEntryFromNode(node)];
}
// the symbol was an internal symbol and does not have a declaration e.g.undefined symbol
if (!symbol.getDeclarations()) {
var declarations = symbol.declarations;
// The symbol was an internal symbol and does not have a declaration e.g.undefined symbol
if (!declarations || !declarations.length) {
return undefined;
}
var result: ReferenceEntry[];
// Compute the meaning from the location and the symbol it references
var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), symbol.getDeclarations());
var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations);
// Get the text to search for, we need to normalize it as external module names will have quote
var symbolName = getNormalizedSymbolName(symbol);
var symbolName = getNormalizedSymbolName(symbol.name, declarations);
// Get syntactic diagnostics
var scope = getSymbolScope(symbol);
@ -3712,15 +3779,15 @@ module ts {
return result;
function getNormalizedSymbolName(symbol: Symbol): string {
function getNormalizedSymbolName(symbolName: string, declarations: Declaration[]): string {
// Special case for function expressions, whose names are solely local to their bodies.
var functionExpression = getDeclarationOfKind(symbol, SyntaxKind.FunctionExpression);
var functionExpression = forEach(declarations, d => d.kind === SyntaxKind.FunctionExpression ? d : undefined);
if (functionExpression && functionExpression.name) {
var name = functionExpression.name.text;
}
else {
var name = symbol.name;
var name = symbolName;
}
var length = name.length;
@ -3747,22 +3814,24 @@ module ts {
var scope: Node = undefined;
var declarations = symbol.getDeclarations();
for (var i = 0, n = declarations.length; i < n; i++) {
var container = getContainerNode(declarations[i]);
if (declarations) {
for (var i = 0, n = declarations.length; i < n; i++) {
var container = getContainerNode(declarations[i]);
if (scope && scope !== container) {
// Different declarations have different containers, bail out
return undefined;
if (scope && scope !== container) {
// Different declarations have different containers, bail out
return undefined;
}
if (container.kind === SyntaxKind.SourceFile && !isExternalModule(<SourceFile>container)) {
// This is a global variable and not an external module, any declaration defined
// within this scope is visible outside the file
return undefined;
}
// The search scope is the container node
scope = container;
}
if (container.kind === SyntaxKind.SourceFile && !isExternalModule(<SourceFile>container)) {
// This is a global variable and not an external module, any declaration defined
// within this scope is visible outside the file
return undefined;
}
// The search scope is the container node
scope = container;
}
return scope;
@ -3898,14 +3967,7 @@ module ts {
}
var referenceSymbol = typeInfoResolver.getSymbolInfo(referenceLocation);
// Could not find a symbol e.g. node is string or number keyword,
// or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
if (!referenceSymbol || !(referenceSymbol.getDeclarations())) {
return;
}
if (isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) {
if (referenceSymbol && isRelatableToSearchSet(searchSymbols, referenceSymbol, referenceLocation)) {
result.push(getReferenceEntryFromNode(referenceLocation));
}
});
@ -4067,24 +4129,27 @@ module ts {
// The search set contains at least the current symbol
var result = [symbol];
// If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list
var rootSymbol = typeInfoResolver.getRootSymbol(symbol);
if (rootSymbol && rootSymbol !== symbol) {
result.push(rootSymbol);
}
// If the location is in a context sensitive location (i.e. in an object literal) try
// to get a contextual type for it, and add the property symbol from the contextual
// type to the search set
if (isNameOfPropertyAssignment(location)) {
var symbolFromContextualType = getPropertySymbolFromContextualType(location);
if (symbolFromContextualType) result.push(typeInfoResolver.getRootSymbol(symbolFromContextualType));
forEach(getPropertySymbolsFromContextualType(location), contextualSymbol => {
result.push.apply(result, typeInfoResolver.getRootSymbols(contextualSymbol));
});
}
// Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions
if (symbol.parent && symbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
getPropertySymbolsFromBaseTypes(symbol.parent, symbol.getName(), result);
}
// If this is a union property, add all the symbols from all its source symbols in all unioned types.
// If the symbol is an instantiation from a another symbol (e.g. widened symbol) , add the root the list
forEach(typeInfoResolver.getRootSymbols(symbol), rootSymbol => {
if (rootSymbol !== symbol) {
result.push(rootSymbol);
}
// Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions
if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result);
}
});
return result;
}
@ -4120,11 +4185,7 @@ module ts {
}
function isRelatableToSearchSet(searchSymbols: Symbol[], referenceSymbol: Symbol, referenceLocation: Node): boolean {
// Unwrap symbols to get to the root (e.g. transient symbols as a result of widening)
var referenceSymbolTarget = typeInfoResolver.getRootSymbol(referenceSymbol);
// if it is in the list, then we are done
if (searchSymbols.indexOf(referenceSymbolTarget) >= 0) {
if (searchSymbols.indexOf(referenceSymbol) >= 0) {
return true;
}
@ -4132,29 +4193,61 @@ module ts {
// object literal, lookup the property symbol in the contextual type, and use this symbol to
// compare to our searchSymbol
if (isNameOfPropertyAssignment(referenceLocation)) {
var symbolFromContextualType = getPropertySymbolFromContextualType(referenceLocation);
if (symbolFromContextualType && searchSymbols.indexOf(typeInfoResolver.getRootSymbol(symbolFromContextualType)) >= 0) {
return forEach(getPropertySymbolsFromContextualType(referenceLocation), contextualSymbol => {
return forEach(typeInfoResolver.getRootSymbols(contextualSymbol), s => searchSymbols.indexOf(s) >= 0);
});
}
// Unwrap symbols to get to the root (e.g. transient symbols as a result of widening)
// Or a union property, use its underlying unioned symbols
return forEach(typeInfoResolver.getRootSymbols(referenceSymbol), rootSymbol => {
// if it is in the list, then we are done
if (searchSymbols.indexOf(rootSymbol) >= 0) {
return true;
}
}
// Finally, try all properties with the same name in any type the containing type extend or implemented, and
// see if any is in the list
if (referenceSymbol.parent && referenceSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
var result: Symbol[] = [];
getPropertySymbolsFromBaseTypes(referenceSymbol.parent, referenceSymbol.getName(), result);
return forEach(result, s => searchSymbols.indexOf(s) >= 0);
}
// Finally, try all properties with the same name in any type the containing type extended or implemented, and
// see if any is in the list
if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
var result: Symbol[] = [];
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result);
return forEach(result, s => searchSymbols.indexOf(s) >= 0);
}
return false;
return false;
});
}
function getPropertySymbolFromContextualType(node: Node): Symbol {
function getPropertySymbolsFromContextualType(node: Node): Symbol[] {
if (isNameOfPropertyAssignment(node)) {
var objectLiteral = node.parent.parent;
var contextualType = typeInfoResolver.getContextualType(objectLiteral);
var name = (<Identifier>node).text;
if (contextualType) {
return typeInfoResolver.getPropertyOfType(contextualType, (<Identifier>node).text);
if (contextualType.flags & TypeFlags.Union) {
// This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types)
// if not, search the constituent types for the property
var unionProperty = contextualType.getProperty(name)
if (unionProperty) {
return [unionProperty];
}
else {
var result: Symbol[] = [];
forEach((<UnionType>contextualType).types, t => {
var symbol = t.getProperty(name);
if (symbol) {
result.push(symbol);
}
});
return result;
}
}
else {
var symbol = contextualType.getProperty(name);
if (symbol) {
return [symbol];
}
}
}
}
return undefined;
@ -4656,7 +4749,6 @@ module ts {
function classifySymbol(symbol: Symbol, meaningAtPosition: SemanticMeaning) {
var flags = symbol.getFlags();
// TODO(drosen): use meaningAtPosition.
if (flags & SymbolFlags.Class) {
return ClassificationTypeNames.className;
}
@ -4672,10 +4764,25 @@ module ts {
}
}
else if (flags & SymbolFlags.Module) {
return ClassificationTypeNames.moduleName;
// Only classify a module as such if
// - It appears in a namespace context.
// - There exists a module declaration which actually impacts the value side.
if (meaningAtPosition & SemanticMeaning.Namespace ||
(meaningAtPosition & SemanticMeaning.Value && hasValueSideModule(symbol))) {
return ClassificationTypeNames.moduleName;
}
}
return undefined;
/**
* Returns true if there exists a module that introduces entities on the value side.
*/
function hasValueSideModule(symbol: Symbol): boolean {
return forEach(symbol.declarations, declaration => {
return declaration.kind === SyntaxKind.ModuleDeclaration && isInstantiated(declaration);
});
}
}
function processNode(node: Node) {
@ -5145,7 +5252,7 @@ module ts {
// Only allow a symbol to be renamed if it actually has at least one declaration.
if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) {
var kind = getSymbolKind(symbol);
var kind = getSymbolKind(symbol, typeInfoResolver);
if (kind) {
return getRenameInfo(symbol.name, typeInfoResolver.getFullyQualifiedName(symbol), kind,
getSymbolModifiers(symbol),

View File

@ -84,7 +84,6 @@ module TypeScript {
private cacheSyntaxTreeInfo(): void {
// If we're not keeping around the syntax tree, store the diagnostics and line
// map so they don't have to be recomputed.
var sourceUnit = this.sourceUnit();
var firstToken = firstSyntaxTreeToken(this);
var leadingTrivia = firstToken.leadingTrivia(this.text);

View File

@ -17,7 +17,7 @@ interface IHasVisualizationModel {
var xs: IHasVisualizationModel[] = [moduleA];
>xs : IHasVisualizationModel[]
>IHasVisualizationModel : IHasVisualizationModel
>[moduleA] : IHasVisualizationModel[]
>[moduleA] : typeof moduleA[]
>moduleA : typeof moduleA
var xs2: typeof moduleA[] = [moduleA];

View File

@ -53,7 +53,7 @@ var f: { x: IHasVisualizationModel } = <{ x: IHasVisualizationModel }>null ? { x
>f : { x: IHasVisualizationModel; }
>x : IHasVisualizationModel
>IHasVisualizationModel : IHasVisualizationModel
><{ x: IHasVisualizationModel }>null ? { x: moduleA } : null : { x: IHasVisualizationModel; }
><{ x: IHasVisualizationModel }>null ? { x: moduleA } : null : { x: typeof moduleA; }
><{ x: IHasVisualizationModel }>null : { x: IHasVisualizationModel; }
>x : IHasVisualizationModel
>IHasVisualizationModel : IHasVisualizationModel

View File

@ -1,55 +1,109 @@
//// [arrayBestCommonTypes.ts]
interface iface { }
class base implements iface { }
class base2 implements iface { }
class derived extends base { }
module EmptyTypes {
interface iface { }
class base implements iface { }
class base2 implements iface { }
class derived extends base { }
class f {
public voidIfAny(x: boolean, y?: boolean): number;
public voidIfAny(x: string, y?: boolean): number;
public voidIfAny(x: number, y?: boolean): number;
public voidIfAny(x: any, y =false): any { return null; }
public x() {
<number>(this.voidIfAny([4, 2][0]));
<number>(this.voidIfAny([4, 2, undefined][0]));
<number>(this.voidIfAny([undefined, 2, 4][0]));
<number>(this.voidIfAny([null, 2, 4][0]));
<number>(this.voidIfAny([2, 4, null][0]));
<number>(this.voidIfAny([undefined, 4, null][0]));
class f {
public voidIfAny(x: boolean, y?: boolean): number;
public voidIfAny(x: string, y?: boolean): number;
public voidIfAny(x: number, y?: boolean): number;
public voidIfAny(x: any, y = false): any { return null; }
<number>(this.voidIfAny(['', "q"][0]));
<number>(this.voidIfAny(['', "q", undefined][0]));
<number>(this.voidIfAny([undefined, "q", ''][0]));
<number>(this.voidIfAny([null, "q", ''][0]));
<number>(this.voidIfAny(["q", '', null][0]));
<number>(this.voidIfAny([undefined, '', null][0]));
public x() {
<number>(this.voidIfAny([4, 2][0]));
<number>(this.voidIfAny([4, 2, undefined][0]));
<number>(this.voidIfAny([undefined, 2, 4][0]));
<number>(this.voidIfAny([null, 2, 4][0]));
<number>(this.voidIfAny([2, 4, null][0]));
<number>(this.voidIfAny([undefined, 4, null][0]));
<number>(this.voidIfAny([[3,4],[null]][0][0]));
var t1: { x: number; y: base; }[] = [ { x: 7, y: new derived() }, { x: 5, y: new base() } ];
var t2: { x: boolean; y: base; }[] = [ { x: true, y: new derived() }, { x: false, y: new base() } ];
var t3: { x: string; y: base; }[] = [ { x: undefined, y: new base() }, { x: '', y: new derived() } ];
<number>(this.voidIfAny(['', "q"][0]));
<number>(this.voidIfAny(['', "q", undefined][0]));
<number>(this.voidIfAny([undefined, "q", ''][0]));
<number>(this.voidIfAny([null, "q", ''][0]));
<number>(this.voidIfAny(["q", '', null][0]));
<number>(this.voidIfAny([undefined, '', null][0]));
var anyObj: any = null;
// Order matters here so test all the variants
var a1 = [ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ];
var a2 = [ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ];
var a3 = [ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ];
var ifaceObj: iface = null;
var baseObj = new base();
var base2Obj = new base2();
<number>(this.voidIfAny([[3, 4], [null]][0][0]));
var b1 = [ baseObj, base2Obj, ifaceObj ];
var b2 = [ base2Obj, baseObj, ifaceObj ];
var b3 = [ baseObj, ifaceObj, base2Obj ];
var b4 = [ ifaceObj, baseObj, base2Obj ];
var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj: any = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj: iface = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
}
}
}
module NonEmptyTypes {
interface iface { x: string; }
class base implements iface { x: string; y: string; }
class base2 implements iface { x: string; z: string; }
class derived extends base { a: string; }
class f {
public voidIfAny(x: boolean, y?: boolean): number;
public voidIfAny(x: string, y?: boolean): number;
public voidIfAny(x: number, y?: boolean): number;
public voidIfAny(x: any, y = false): any { return null; }
public x() {
<number>(this.voidIfAny([4, 2][0]));
<number>(this.voidIfAny([4, 2, undefined][0]));
<number>(this.voidIfAny([undefined, 2, 4][0]));
<number>(this.voidIfAny([null, 2, 4][0]));
<number>(this.voidIfAny([2, 4, null][0]));
<number>(this.voidIfAny([undefined, 4, null][0]));
<number>(this.voidIfAny(['', "q"][0]));
<number>(this.voidIfAny(['', "q", undefined][0]));
<number>(this.voidIfAny([undefined, "q", ''][0]));
<number>(this.voidIfAny([null, "q", ''][0]));
<number>(this.voidIfAny(["q", '', null][0]));
<number>(this.voidIfAny([undefined, '', null][0]));
<number>(this.voidIfAny([[3, 4], [null]][0][0]));
var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj: any = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj: iface = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
}
}
}
@ -60,59 +114,121 @@ var __extends = this.__extends || function (d, b) {
__.prototype = b.prototype;
d.prototype = new __();
};
var base = (function () {
function base() {
}
return base;
})();
var base2 = (function () {
function base2() {
}
return base2;
})();
var derived = (function (_super) {
__extends(derived, _super);
function derived() {
_super.apply(this, arguments);
}
return derived;
})(base);
var f = (function () {
function f() {
}
f.prototype.voidIfAny = function (x, y) {
if (y === void 0) { y = false; }
return null;
};
f.prototype.x = function () {
(this.voidIfAny([4, 2][0]));
(this.voidIfAny([4, 2, undefined][0]));
(this.voidIfAny([undefined, 2, 4][0]));
(this.voidIfAny([null, 2, 4][0]));
(this.voidIfAny([2, 4, null][0]));
(this.voidIfAny([undefined, 4, null][0]));
(this.voidIfAny(['', "q"][0]));
(this.voidIfAny(['', "q", undefined][0]));
(this.voidIfAny([undefined, "q", ''][0]));
(this.voidIfAny([null, "q", ''][0]));
(this.voidIfAny(["q", '', null][0]));
(this.voidIfAny([undefined, '', null][0]));
(this.voidIfAny([[3, 4], [null]][0][0]));
var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
};
return f;
})();
var EmptyTypes;
(function (EmptyTypes) {
var base = (function () {
function base() {
}
return base;
})();
var base2 = (function () {
function base2() {
}
return base2;
})();
var derived = (function (_super) {
__extends(derived, _super);
function derived() {
_super.apply(this, arguments);
}
return derived;
})(base);
var f = (function () {
function f() {
}
f.prototype.voidIfAny = function (x, y) {
if (y === void 0) { y = false; }
return null;
};
f.prototype.x = function () {
(this.voidIfAny([4, 2][0]));
(this.voidIfAny([4, 2, undefined][0]));
(this.voidIfAny([undefined, 2, 4][0]));
(this.voidIfAny([null, 2, 4][0]));
(this.voidIfAny([2, 4, null][0]));
(this.voidIfAny([undefined, 4, null][0]));
(this.voidIfAny(['', "q"][0]));
(this.voidIfAny(['', "q", undefined][0]));
(this.voidIfAny([undefined, "q", ''][0]));
(this.voidIfAny([null, "q", ''][0]));
(this.voidIfAny(["q", '', null][0]));
(this.voidIfAny([undefined, '', null][0]));
(this.voidIfAny([[3, 4], [null]][0][0]));
var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
};
return f;
})();
})(EmptyTypes || (EmptyTypes = {}));
var NonEmptyTypes;
(function (NonEmptyTypes) {
var base = (function () {
function base() {
}
return base;
})();
var base2 = (function () {
function base2() {
}
return base2;
})();
var derived = (function (_super) {
__extends(derived, _super);
function derived() {
_super.apply(this, arguments);
}
return derived;
})(base);
var f = (function () {
function f() {
}
f.prototype.voidIfAny = function (x, y) {
if (y === void 0) { y = false; }
return null;
};
f.prototype.x = function () {
(this.voidIfAny([4, 2][0]));
(this.voidIfAny([4, 2, undefined][0]));
(this.voidIfAny([undefined, 2, 4][0]));
(this.voidIfAny([null, 2, 4][0]));
(this.voidIfAny([2, 4, null][0]));
(this.voidIfAny([undefined, 4, null][0]));
(this.voidIfAny(['', "q"][0]));
(this.voidIfAny(['', "q", undefined][0]));
(this.voidIfAny([undefined, "q", ''][0]));
(this.voidIfAny([null, "q", ''][0]));
(this.voidIfAny(["q", '', null][0]));
(this.voidIfAny([undefined, '', null][0]));
(this.voidIfAny([[3, 4], [null]][0][0]));
var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
};
return f;
})();
})(NonEmptyTypes || (NonEmptyTypes = {}));

View File

@ -1,47 +1,50 @@
=== tests/cases/compiler/arrayBestCommonTypes.ts ===
interface iface { }
module EmptyTypes {
>EmptyTypes : typeof EmptyTypes
interface iface { }
>iface : iface
class base implements iface { }
class base implements iface { }
>base : base
>iface : iface
class base2 implements iface { }
class base2 implements iface { }
>base2 : base2
>iface : iface
class derived extends base { }
class derived extends base { }
>derived : derived
>base : base
class f {
class f {
>f : f
public voidIfAny(x: boolean, y?: boolean): number;
public voidIfAny(x: boolean, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : boolean
>y : boolean
public voidIfAny(x: string, y?: boolean): number;
public voidIfAny(x: string, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : string
>y : boolean
public voidIfAny(x: number, y?: boolean): number;
public voidIfAny(x: number, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : number
>y : boolean
public voidIfAny(x: any, y =false): any { return null; }
public voidIfAny(x: any, y = false): any { return null; }
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : any
>y : boolean
public x() {
public x() {
>x : () => void
<number>(this.voidIfAny([4, 2][0]));
<number>(this.voidIfAny([4, 2][0]));
><number>(this.voidIfAny([4, 2][0])) : number
>(this.voidIfAny([4, 2][0])) : number
>this.voidIfAny([4, 2][0]) : number
@ -51,7 +54,7 @@ class f {
>[4, 2][0] : number
>[4, 2] : number[]
<number>(this.voidIfAny([4, 2, undefined][0]));
<number>(this.voidIfAny([4, 2, undefined][0]));
><number>(this.voidIfAny([4, 2, undefined][0])) : number
>(this.voidIfAny([4, 2, undefined][0])) : number
>this.voidIfAny([4, 2, undefined][0]) : number
@ -62,7 +65,7 @@ class f {
>[4, 2, undefined] : number[]
>undefined : undefined
<number>(this.voidIfAny([undefined, 2, 4][0]));
<number>(this.voidIfAny([undefined, 2, 4][0]));
><number>(this.voidIfAny([undefined, 2, 4][0])) : number
>(this.voidIfAny([undefined, 2, 4][0])) : number
>this.voidIfAny([undefined, 2, 4][0]) : number
@ -73,7 +76,7 @@ class f {
>[undefined, 2, 4] : number[]
>undefined : undefined
<number>(this.voidIfAny([null, 2, 4][0]));
<number>(this.voidIfAny([null, 2, 4][0]));
><number>(this.voidIfAny([null, 2, 4][0])) : number
>(this.voidIfAny([null, 2, 4][0])) : number
>this.voidIfAny([null, 2, 4][0]) : number
@ -83,7 +86,7 @@ class f {
>[null, 2, 4][0] : number
>[null, 2, 4] : number[]
<number>(this.voidIfAny([2, 4, null][0]));
<number>(this.voidIfAny([2, 4, null][0]));
><number>(this.voidIfAny([2, 4, null][0])) : number
>(this.voidIfAny([2, 4, null][0])) : number
>this.voidIfAny([2, 4, null][0]) : number
@ -93,7 +96,7 @@ class f {
>[2, 4, null][0] : number
>[2, 4, null] : number[]
<number>(this.voidIfAny([undefined, 4, null][0]));
<number>(this.voidIfAny([undefined, 4, null][0]));
><number>(this.voidIfAny([undefined, 4, null][0])) : number
>(this.voidIfAny([undefined, 4, null][0])) : number
>this.voidIfAny([undefined, 4, null][0]) : number
@ -104,7 +107,7 @@ class f {
>[undefined, 4, null] : number[]
>undefined : undefined
<number>(this.voidIfAny(['', "q"][0]));
<number>(this.voidIfAny(['', "q"][0]));
><number>(this.voidIfAny(['', "q"][0])) : number
>(this.voidIfAny(['', "q"][0])) : number
>this.voidIfAny(['', "q"][0]) : number
@ -114,7 +117,7 @@ class f {
>['', "q"][0] : string
>['', "q"] : string[]
<number>(this.voidIfAny(['', "q", undefined][0]));
<number>(this.voidIfAny(['', "q", undefined][0]));
><number>(this.voidIfAny(['', "q", undefined][0])) : number
>(this.voidIfAny(['', "q", undefined][0])) : number
>this.voidIfAny(['', "q", undefined][0]) : number
@ -125,7 +128,7 @@ class f {
>['', "q", undefined] : string[]
>undefined : undefined
<number>(this.voidIfAny([undefined, "q", ''][0]));
<number>(this.voidIfAny([undefined, "q", ''][0]));
><number>(this.voidIfAny([undefined, "q", ''][0])) : number
>(this.voidIfAny([undefined, "q", ''][0])) : number
>this.voidIfAny([undefined, "q", ''][0]) : number
@ -136,7 +139,7 @@ class f {
>[undefined, "q", ''] : string[]
>undefined : undefined
<number>(this.voidIfAny([null, "q", ''][0]));
<number>(this.voidIfAny([null, "q", ''][0]));
><number>(this.voidIfAny([null, "q", ''][0])) : number
>(this.voidIfAny([null, "q", ''][0])) : number
>this.voidIfAny([null, "q", ''][0]) : number
@ -146,7 +149,7 @@ class f {
>[null, "q", ''][0] : string
>[null, "q", ''] : string[]
<number>(this.voidIfAny(["q", '', null][0]));
<number>(this.voidIfAny(["q", '', null][0]));
><number>(this.voidIfAny(["q", '', null][0])) : number
>(this.voidIfAny(["q", '', null][0])) : number
>this.voidIfAny(["q", '', null][0]) : number
@ -156,7 +159,7 @@ class f {
>["q", '', null][0] : string
>["q", '', null] : string[]
<number>(this.voidIfAny([undefined, '', null][0]));
<number>(this.voidIfAny([undefined, '', null][0]));
><number>(this.voidIfAny([undefined, '', null][0])) : number
>(this.voidIfAny([undefined, '', null][0])) : number
>this.voidIfAny([undefined, '', null][0]) : number
@ -167,26 +170,26 @@ class f {
>[undefined, '', null] : string[]
>undefined : undefined
<number>(this.voidIfAny([[3,4],[null]][0][0]));
><number>(this.voidIfAny([[3,4],[null]][0][0])) : number
>(this.voidIfAny([[3,4],[null]][0][0])) : number
>this.voidIfAny([[3,4],[null]][0][0]) : number
<number>(this.voidIfAny([[3, 4], [null]][0][0]));
><number>(this.voidIfAny([[3, 4], [null]][0][0])) : number
>(this.voidIfAny([[3, 4], [null]][0][0])) : number
>this.voidIfAny([[3, 4], [null]][0][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[[3,4],[null]][0][0] : number
>[[3,4],[null]][0] : number[]
>[[3,4],[null]] : number[][]
>[3,4] : number[]
>[[3, 4], [null]][0][0] : number
>[[3, 4], [null]][0] : number[]
>[[3, 4], [null]] : number[][]
>[3, 4] : number[]
>[null] : null[]
var t1: { x: number; y: base; }[] = [ { x: 7, y: new derived() }, { x: 5, y: new base() } ];
var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
>t1 : { x: number; y: base; }[]
>x : number
>y : base
>base : base
>[ { x: 7, y: new derived() }, { x: 5, y: new base() } ] : { x: number; y: base; }[]
>[{ x: 7, y: new derived() }, { x: 5, y: new base() }] : { x: number; y: derived; }[]
>{ x: 7, y: new derived() } : { x: number; y: derived; }
>x : number
>y : derived
@ -198,12 +201,12 @@ class f {
>new base() : base
>base : typeof base
var t2: { x: boolean; y: base; }[] = [ { x: true, y: new derived() }, { x: false, y: new base() } ];
var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }];
>t2 : { x: boolean; y: base; }[]
>x : boolean
>y : base
>base : base
>[ { x: true, y: new derived() }, { x: false, y: new base() } ] : { x: boolean; y: base; }[]
>[{ x: true, y: new derived() }, { x: false, y: new base() }] : { x: boolean; y: derived; }[]
>{ x: true, y: new derived() } : { x: boolean; y: derived; }
>x : boolean
>y : derived
@ -215,12 +218,12 @@ class f {
>new base() : base
>base : typeof base
var t3: { x: string; y: base; }[] = [ { x: undefined, y: new base() }, { x: '', y: new derived() } ];
var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
>t3 : { x: string; y: base; }[]
>x : string
>y : base
>base : base
>[ { x: undefined, y: new base() }, { x: '', y: new derived() } ] : { x: string; y: base; }[]
>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : { x: string; y: derived; }[]
>{ x: undefined, y: new base() } : { x: undefined; y: base; }
>x : undefined
>undefined : undefined
@ -233,95 +236,429 @@ class f {
>new derived() : derived
>derived : typeof derived
var anyObj: any = null;
var anyObj: any = null;
>anyObj : any
// Order matters here so test all the variants
var a1 = [ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ];
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
>a1 : { x: any; y: string; }[]
>[ {x: 0, y: 'a'}, {x: 'a', y: 'a'}, {x: anyObj, y: 'a'} ] : { x: any; y: string; }[]
>{x: 0, y: 'a'} : { x: number; y: string; }
>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : { x: any; y: string; }[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{x: 'a', y: 'a'} : { x: string; y: string; }
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
>{x: anyObj, y: 'a'} : { x: any; y: string; }
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
var a2 = [ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
>a2 : { x: any; y: string; }[]
>[ {x: anyObj, y: 'a'}, {x: 0, y: 'a'}, {x: 'a', y: 'a'} ] : { x: any; y: string; }[]
>{x: anyObj, y: 'a'} : { x: any; y: string; }
>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[]
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
>{x: 0, y: 'a'} : { x: number; y: string; }
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{x: 'a', y: 'a'} : { x: string; y: string; }
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
var a3 = [ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
>a3 : { x: any; y: string; }[]
>[ {x: 0, y: 'a'}, {x: anyObj, y: 'a'}, {x: 'a', y: 'a'} ] : { x: any; y: string; }[]
>{x: 0, y: 'a'} : { x: number; y: string; }
>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{x: anyObj, y: 'a'} : { x: any; y: string; }
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
>{x: 'a', y: 'a'} : { x: string; y: string; }
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
var ifaceObj: iface = null;
var ifaceObj: iface = null;
>ifaceObj : iface
>iface : iface
var baseObj = new base();
var baseObj = new base();
>baseObj : base
>new base() : base
>base : typeof base
var base2Obj = new base2();
var base2Obj = new base2();
>base2Obj : base2
>new base2() : base2
>base2 : typeof base2
var b1 = [ baseObj, base2Obj, ifaceObj ];
>b1 : base[]
>[ baseObj, base2Obj, ifaceObj ] : base[]
var b1 = [baseObj, base2Obj, ifaceObj];
>b1 : iface[]
>[baseObj, base2Obj, ifaceObj] : iface[]
>baseObj : base
>base2Obj : base2
>ifaceObj : iface
var b2 = [ base2Obj, baseObj, ifaceObj ];
>b2 : base2[]
>[ base2Obj, baseObj, ifaceObj ] : base2[]
var b2 = [base2Obj, baseObj, ifaceObj];
>b2 : iface[]
>[base2Obj, baseObj, ifaceObj] : iface[]
>base2Obj : base2
>baseObj : base
>ifaceObj : iface
var b3 = [ baseObj, ifaceObj, base2Obj ];
>b3 : base[]
>[ baseObj, ifaceObj, base2Obj ] : base[]
var b3 = [baseObj, ifaceObj, base2Obj];
>b3 : iface[]
>[baseObj, ifaceObj, base2Obj] : iface[]
>baseObj : base
>ifaceObj : iface
>base2Obj : base2
var b4 = [ ifaceObj, baseObj, base2Obj ];
var b4 = [ifaceObj, baseObj, base2Obj];
>b4 : iface[]
>[ ifaceObj, baseObj, base2Obj ] : iface[]
>[ifaceObj, baseObj, base2Obj] : iface[]
>ifaceObj : iface
>baseObj : base
>base2Obj : base2
}
}
}
module NonEmptyTypes {
>NonEmptyTypes : typeof NonEmptyTypes
interface iface { x: string; }
>iface : iface
>x : string
class base implements iface { x: string; y: string; }
>base : base
>iface : iface
>x : string
>y : string
class base2 implements iface { x: string; z: string; }
>base2 : base2
>iface : iface
>x : string
>z : string
class derived extends base { a: string; }
>derived : derived
>base : base
>a : string
class f {
>f : f
public voidIfAny(x: boolean, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : boolean
>y : boolean
public voidIfAny(x: string, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : string
>y : boolean
public voidIfAny(x: number, y?: boolean): number;
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : number
>y : boolean
public voidIfAny(x: any, y = false): any { return null; }
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>x : any
>y : boolean
public x() {
>x : () => void
<number>(this.voidIfAny([4, 2][0]));
><number>(this.voidIfAny([4, 2][0])) : number
>(this.voidIfAny([4, 2][0])) : number
>this.voidIfAny([4, 2][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[4, 2][0] : number
>[4, 2] : number[]
<number>(this.voidIfAny([4, 2, undefined][0]));
><number>(this.voidIfAny([4, 2, undefined][0])) : number
>(this.voidIfAny([4, 2, undefined][0])) : number
>this.voidIfAny([4, 2, undefined][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[4, 2, undefined][0] : number
>[4, 2, undefined] : number[]
>undefined : undefined
<number>(this.voidIfAny([undefined, 2, 4][0]));
><number>(this.voidIfAny([undefined, 2, 4][0])) : number
>(this.voidIfAny([undefined, 2, 4][0])) : number
>this.voidIfAny([undefined, 2, 4][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[undefined, 2, 4][0] : number
>[undefined, 2, 4] : number[]
>undefined : undefined
<number>(this.voidIfAny([null, 2, 4][0]));
><number>(this.voidIfAny([null, 2, 4][0])) : number
>(this.voidIfAny([null, 2, 4][0])) : number
>this.voidIfAny([null, 2, 4][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[null, 2, 4][0] : number
>[null, 2, 4] : number[]
<number>(this.voidIfAny([2, 4, null][0]));
><number>(this.voidIfAny([2, 4, null][0])) : number
>(this.voidIfAny([2, 4, null][0])) : number
>this.voidIfAny([2, 4, null][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[2, 4, null][0] : number
>[2, 4, null] : number[]
<number>(this.voidIfAny([undefined, 4, null][0]));
><number>(this.voidIfAny([undefined, 4, null][0])) : number
>(this.voidIfAny([undefined, 4, null][0])) : number
>this.voidIfAny([undefined, 4, null][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[undefined, 4, null][0] : number
>[undefined, 4, null] : number[]
>undefined : undefined
<number>(this.voidIfAny(['', "q"][0]));
><number>(this.voidIfAny(['', "q"][0])) : number
>(this.voidIfAny(['', "q"][0])) : number
>this.voidIfAny(['', "q"][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>['', "q"][0] : string
>['', "q"] : string[]
<number>(this.voidIfAny(['', "q", undefined][0]));
><number>(this.voidIfAny(['', "q", undefined][0])) : number
>(this.voidIfAny(['', "q", undefined][0])) : number
>this.voidIfAny(['', "q", undefined][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>['', "q", undefined][0] : string
>['', "q", undefined] : string[]
>undefined : undefined
<number>(this.voidIfAny([undefined, "q", ''][0]));
><number>(this.voidIfAny([undefined, "q", ''][0])) : number
>(this.voidIfAny([undefined, "q", ''][0])) : number
>this.voidIfAny([undefined, "q", ''][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[undefined, "q", ''][0] : string
>[undefined, "q", ''] : string[]
>undefined : undefined
<number>(this.voidIfAny([null, "q", ''][0]));
><number>(this.voidIfAny([null, "q", ''][0])) : number
>(this.voidIfAny([null, "q", ''][0])) : number
>this.voidIfAny([null, "q", ''][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[null, "q", ''][0] : string
>[null, "q", ''] : string[]
<number>(this.voidIfAny(["q", '', null][0]));
><number>(this.voidIfAny(["q", '', null][0])) : number
>(this.voidIfAny(["q", '', null][0])) : number
>this.voidIfAny(["q", '', null][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>["q", '', null][0] : string
>["q", '', null] : string[]
<number>(this.voidIfAny([undefined, '', null][0]));
><number>(this.voidIfAny([undefined, '', null][0])) : number
>(this.voidIfAny([undefined, '', null][0])) : number
>this.voidIfAny([undefined, '', null][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[undefined, '', null][0] : string
>[undefined, '', null] : string[]
>undefined : undefined
<number>(this.voidIfAny([[3, 4], [null]][0][0]));
><number>(this.voidIfAny([[3, 4], [null]][0][0])) : number
>(this.voidIfAny([[3, 4], [null]][0][0])) : number
>this.voidIfAny([[3, 4], [null]][0][0]) : number
>this.voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>this : f
>voidIfAny : { (x: boolean, y?: boolean): number; (x: string, y?: boolean): number; (x: number, y?: boolean): number; }
>[[3, 4], [null]][0][0] : number
>[[3, 4], [null]][0] : number[]
>[[3, 4], [null]] : number[][]
>[3, 4] : number[]
>[null] : null[]
var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
>t1 : { x: number; y: base; }[]
>x : number
>y : base
>base : base
>[{ x: 7, y: new derived() }, { x: 5, y: new base() }] : { x: number; y: base; }[]
>{ x: 7, y: new derived() } : { x: number; y: derived; }
>x : number
>y : derived
>new derived() : derived
>derived : typeof derived
>{ x: 5, y: new base() } : { x: number; y: base; }
>x : number
>y : base
>new base() : base
>base : typeof base
var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }];
>t2 : { x: boolean; y: base; }[]
>x : boolean
>y : base
>base : base
>[{ x: true, y: new derived() }, { x: false, y: new base() }] : { x: boolean; y: base; }[]
>{ x: true, y: new derived() } : { x: boolean; y: derived; }
>x : boolean
>y : derived
>new derived() : derived
>derived : typeof derived
>{ x: false, y: new base() } : { x: boolean; y: base; }
>x : boolean
>y : base
>new base() : base
>base : typeof base
var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
>t3 : { x: string; y: base; }[]
>x : string
>y : base
>base : base
>[{ x: undefined, y: new base() }, { x: '', y: new derived() }] : Array<{ x: undefined; y: base; } | { x: string; y: derived; }>
>{ x: undefined, y: new base() } : { x: undefined; y: base; }
>x : undefined
>undefined : undefined
>y : base
>new base() : base
>base : typeof base
>{ x: '', y: new derived() } : { x: string; y: derived; }
>x : string
>y : derived
>new derived() : derived
>derived : typeof derived
var anyObj: any = null;
>anyObj : any
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
>a1 : { x: any; y: string; }[]
>[{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }] : { x: any; y: string; }[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
>a2 : { x: any; y: string; }[]
>[{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[]
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
>a3 : { x: any; y: string; }[]
>[{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }] : { x: any; y: string; }[]
>{ x: 0, y: 'a' } : { x: number; y: string; }
>x : number
>y : string
>{ x: anyObj, y: 'a' } : { x: any; y: string; }
>x : any
>anyObj : any
>y : string
>{ x: 'a', y: 'a' } : { x: string; y: string; }
>x : string
>y : string
var ifaceObj: iface = null;
>ifaceObj : iface
>iface : iface
var baseObj = new base();
>baseObj : base
>new base() : base
>base : typeof base
var base2Obj = new base2();
>base2Obj : base2
>new base2() : base2
>base2 : typeof base2
var b1 = [baseObj, base2Obj, ifaceObj];
>b1 : iface[]
>[baseObj, base2Obj, ifaceObj] : iface[]
>baseObj : base
>base2Obj : base2
>ifaceObj : iface
var b2 = [base2Obj, baseObj, ifaceObj];
>b2 : iface[]
>[base2Obj, baseObj, ifaceObj] : iface[]
>base2Obj : base2
>baseObj : base
>ifaceObj : iface
var b3 = [baseObj, ifaceObj, base2Obj];
>b3 : iface[]
>[baseObj, ifaceObj, base2Obj] : iface[]
>baseObj : base
>ifaceObj : iface
>base2Obj : base2
var b4 = [ifaceObj, baseObj, base2Obj];
>b4 : iface[]
>[ifaceObj, baseObj, base2Obj] : iface[]
>ifaceObj : iface
>baseObj : base
>base2Obj : base2
}
}
}

View File

@ -1,7 +1,7 @@
=== tests/cases/compiler/arrayConcat2.ts ===
var a: string[] = [];
>a : string[]
>[] : string[]
>[] : undefined[]
a.concat("hello", 'world');
>a.concat("hello", 'world') : string[]

View File

@ -25,7 +25,7 @@ var y = new Array<number>();
var x2: number[] = [];
>x2 : number[]
>[] : number[]
>[] : undefined[]
var x2: number[] = new Array(1);
>x2 : number[]

View File

@ -1,40 +0,0 @@
tests/cases/compiler/arrayLiteralContextualType.ts(28,5): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'.
Type '{}' is not assignable to type 'IAnimal'.
tests/cases/compiler/arrayLiteralContextualType.ts(29,5): error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'.
==== tests/cases/compiler/arrayLiteralContextualType.ts (2 errors) ====
interface IAnimal {
name: string;
}
class Giraffe {
name = "Giraffe";
neckLength = "3m";
}
class Elephant {
name = "Elephant";
trunkDiameter = "20cm";
}
function foo(animals: IAnimal[]) { }
function bar(animals: { [n: number]: IAnimal }) { }
foo([
new Giraffe(),
new Elephant()
]); // Legal because of the contextual type IAnimal provided by the parameter
bar([
new Giraffe(),
new Elephant()
]); // Legal because of the contextual type IAnimal provided by the parameter
var arr = [new Giraffe(), new Elephant()];
foo(arr); // Error because of no contextual type
~~~
!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'IAnimal[]'.
!!! error TS2345: Type '{}' is not assignable to type 'IAnimal'.
bar(arr); // Error because of no contextual type
~~~
!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ [x: number]: IAnimal; }'.

View File

@ -26,8 +26,8 @@ bar([
]); // Legal because of the contextual type IAnimal provided by the parameter
var arr = [new Giraffe(), new Elephant()];
foo(arr); // Error because of no contextual type
bar(arr); // Error because of no contextual type
foo(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
bar(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
//// [arrayLiteralContextualType.js]
var Giraffe = (function () {
@ -57,5 +57,5 @@ bar([
new Elephant()
]); // Legal because of the contextual type IAnimal provided by the parameter
var arr = [new Giraffe(), new Elephant()];
foo(arr); // Error because of no contextual type
bar(arr); // Error because of no contextual type
foo(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
bar(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]

View File

@ -0,0 +1,86 @@
=== tests/cases/compiler/arrayLiteralContextualType.ts ===
interface IAnimal {
>IAnimal : IAnimal
name: string;
>name : string
}
class Giraffe {
>Giraffe : Giraffe
name = "Giraffe";
>name : string
neckLength = "3m";
>neckLength : string
}
class Elephant {
>Elephant : Elephant
name = "Elephant";
>name : string
trunkDiameter = "20cm";
>trunkDiameter : string
}
function foo(animals: IAnimal[]) { }
>foo : (animals: IAnimal[]) => void
>animals : IAnimal[]
>IAnimal : IAnimal
function bar(animals: { [n: number]: IAnimal }) { }
>bar : (animals: { [x: number]: IAnimal; }) => void
>animals : { [x: number]: IAnimal; }
>n : number
>IAnimal : IAnimal
foo([
>foo([ new Giraffe(), new Elephant()]) : void
>foo : (animals: IAnimal[]) => void
>[ new Giraffe(), new Elephant()] : Array<Giraffe | Elephant>
new Giraffe(),
>new Giraffe() : Giraffe
>Giraffe : typeof Giraffe
new Elephant()
>new Elephant() : Elephant
>Elephant : typeof Elephant
]); // Legal because of the contextual type IAnimal provided by the parameter
bar([
>bar([ new Giraffe(), new Elephant()]) : void
>bar : (animals: { [x: number]: IAnimal; }) => void
>[ new Giraffe(), new Elephant()] : Array<Giraffe | Elephant>
new Giraffe(),
>new Giraffe() : Giraffe
>Giraffe : typeof Giraffe
new Elephant()
>new Elephant() : Elephant
>Elephant : typeof Elephant
]); // Legal because of the contextual type IAnimal provided by the parameter
var arr = [new Giraffe(), new Elephant()];
>arr : Array<Giraffe | Elephant>
>[new Giraffe(), new Elephant()] : Array<Giraffe | Elephant>
>new Giraffe() : Giraffe
>Giraffe : typeof Giraffe
>new Elephant() : Elephant
>Elephant : typeof Elephant
foo(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
>foo(arr) : void
>foo : (animals: IAnimal[]) => void
>arr : Array<Giraffe | Elephant>
bar(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
>bar(arr) : void
>bar : (animals: { [x: number]: IAnimal; }) => void
>arr : Array<Giraffe | Elephant>

View File

@ -7,5 +7,5 @@ function panic(val: string[], ...opt: string[]) { }
panic([], 'one', 'two');
>panic([], 'one', 'two') : void
>panic : (val: string[], ...opt: string[]) => void
>[] : string[]
>[] : undefined[]

View File

@ -25,7 +25,7 @@ class ActionB extends Action {
var x1: Action[] = [
>x1 : Action[]
>Action : Action
>[ { id: 2, trueness: false }, { id: 3, name: "three" }] : Action[]
>[ { id: 2, trueness: false }, { id: 3, name: "three" }] : Array<{ id: number; trueness: boolean; } | { id: number; name: string; }>
{ id: 2, trueness: false },
>{ id: 2, trueness: false } : { id: number; trueness: boolean; }
@ -42,7 +42,7 @@ var x1: Action[] = [
var x2: Action[] = [
>x2 : Action[]
>Action : Action
>[ new ActionA(), new ActionB()] : Action[]
>[ new ActionA(), new ActionB()] : Array<ActionA | ActionB>
new ActionA(),
>new ActionA() : ActionA
@ -78,7 +78,7 @@ var z1: { id: number }[] =
>id : number
[
>[ { id: 2, trueness: false }, { id: 3, name: "three" } ] : { id: number; }[]
>[ { id: 2, trueness: false }, { id: 3, name: "three" } ] : Array<{ id: number; trueness: boolean; } | { id: number; name: string; }>
{ id: 2, trueness: false },
>{ id: 2, trueness: false } : { id: number; trueness: boolean; }
@ -97,7 +97,7 @@ var z2: { id: number }[] =
>id : number
[
>[ new ActionA(), new ActionB() ] : { id: number; }[]
>[ new ActionA(), new ActionB() ] : Array<ActionA | ActionB>
new ActionA(),
>new ActionA() : ActionA
@ -114,7 +114,7 @@ var z3: { id: number }[] =
>id : number
[
>[ new Action(), new ActionA(), new ActionB() ] : { id: number; }[]
>[ new Action(), new ActionA(), new ActionB() ] : Action[]
new Action(),
>new Action() : Action

View File

@ -23,8 +23,8 @@ var as = [a, b]; // { x: number; y?: number };[]
>b : { x: number; z?: number; }
var bs = [b, a]; // { x: number; z?: number };[]
>bs : { x: number; z?: number; }[]
>[b, a] : { x: number; z?: number; }[]
>bs : { x: number; y?: number; }[]
>[b, a] : { x: number; y?: number; }[]
>b : { x: number; z?: number; }
>a : { x: number; y?: number; }

View File

@ -2,28 +2,21 @@
// Empty array literal with no contextual type has type Undefined[]
var arr1= [[], [1], ['']];
var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
var arr2 = [[null], [1], ['']];
var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
// Array literal with elements of only EveryType E has type E[]
var stringArrArr = [[''], [""]];
var stringArrArr: string[][];
var stringArr = ['', ""];
var stringArr: string[];
var numberArr = [0, 0.0, 0x00, 1e1];
var numberArr: number[];
var boolArr = [false, true, false, true];
var boolArr: boolean[];
class C { private p; }
var classArr = [new C(), new C()];
var classArr: C[]; // Should be OK
var classTypeArray = [C, C, C];
var classTypeArray: Array<typeof C>; // Should OK, not be a parse error
@ -31,7 +24,6 @@ var classTypeArray: Array<typeof C>; // Should OK, not be a parse error
// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[]
var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
var context2: Array<{}>; // Should be OK
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
class Base { private p; }
@ -53,31 +45,23 @@ var __extends = this.__extends || function (d, b) {
d.prototype = new __();
};
var arr1 = [[], [1], ['']];
var arr1; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
var arr2 = [[null], [1], ['']];
var arr2; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
// Array literal with elements of only EveryType E has type E[]
var stringArrArr = [[''], [""]];
var stringArrArr;
var stringArr = ['', ""];
var stringArr;
var numberArr = [0, 0.0, 0x00, 1e1];
var numberArr;
var boolArr = [false, true, false, true];
var boolArr;
var C = (function () {
function C() {
}
return C;
})();
var classArr = [new C(), new C()];
var classArr; // Should be OK
var classTypeArray = [C, C, C];
var classTypeArray; // Should OK, not be a parse error
// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[]
var context1 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
var context2; // Should be OK
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
var Base = (function () {
function Base() {

View File

@ -2,25 +2,19 @@
// Empty array literal with no contextual type has type Undefined[]
var arr1= [[], [1], ['']];
>arr1 : {}[]
>[[], [1], ['']] : {}[]
>arr1 : Array<string[] | number[]>
>[[], [1], ['']] : Array<string[] | number[]>
>[] : undefined[]
>[1] : number[]
>[''] : string[]
var arr1: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
>arr1 : {}[]
var arr2 = [[null], [1], ['']];
>arr2 : {}[]
>[[null], [1], ['']] : {}[]
>arr2 : Array<string[] | number[]>
>[[null], [1], ['']] : Array<string[] | number[]>
>[null] : null[]
>[1] : number[]
>[''] : string[]
var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK
>arr2 : {}[]
// Array literal with elements of only EveryType E has type E[]
var stringArrArr = [[''], [""]];
@ -29,30 +23,18 @@ var stringArrArr = [[''], [""]];
>[''] : string[]
>[""] : string[]
var stringArrArr: string[][];
>stringArrArr : string[][]
var stringArr = ['', ""];
>stringArr : string[]
>['', ""] : string[]
var stringArr: string[];
>stringArr : string[]
var numberArr = [0, 0.0, 0x00, 1e1];
>numberArr : number[]
>[0, 0.0, 0x00, 1e1] : number[]
var numberArr: number[];
>numberArr : number[]
var boolArr = [false, true, false, true];
>boolArr : boolean[]
>[false, true, false, true] : boolean[]
var boolArr: boolean[];
>boolArr : boolean[]
class C { private p; }
>C : C
>p : any
@ -65,10 +47,6 @@ var classArr = [new C(), new C()];
>new C() : C
>C : typeof C
var classArr: C[]; // Should be OK
>classArr : C[]
>C : C
var classTypeArray = [C, C, C];
>classTypeArray : typeof C[]
>[C, C, C] : typeof C[]
@ -87,7 +65,7 @@ var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '
>n : number
>a : string
>b : number
>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : { a: string; b: number; }[]
>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }>
>{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; }
>a : string
>b : number
@ -98,8 +76,8 @@ var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '
>c : number
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
>context2 : {}[]
>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : {}[]
>context2 : Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }>
>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }>
>{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; }
>a : string
>b : number
@ -109,10 +87,6 @@ var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
>b : number
>c : number
var context2: Array<{}>; // Should be OK
>context2 : {}[]
>Array : T[]
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
class Base { private p; }
>Base : Base
@ -131,7 +105,7 @@ class Derived2 extends Base { private n };
var context3: Base[] = [new Derived1(), new Derived2()];
>context3 : Base[]
>Base : Base
>[new Derived1(), new Derived2()] : Base[]
>[new Derived1(), new Derived2()] : Array<Derived1 | Derived2>
>new Derived1() : Derived1
>Derived1 : typeof Derived1
>new Derived2() : Derived2
@ -141,7 +115,7 @@ var context3: Base[] = [new Derived1(), new Derived2()];
var context4: Base[] = [new Derived1(), new Derived1()];
>context4 : Base[]
>Base : Base
>[new Derived1(), new Derived1()] : Base[]
>[new Derived1(), new Derived1()] : Derived1[]
>new Derived1() : Derived1
>Derived1 : typeof Derived1
>new Derived1() : Derived1

View File

@ -61,8 +61,8 @@ var xs = [list, myList]; // {}[]
>myList : MyList<number>
var ys = [list, list2]; // {}[]
>ys : {}[]
>[list, list2] : {}[]
>ys : Array<List<number> | List<string>>
>[list, list2] : Array<List<number> | List<string>>
>list : List<number>
>list2 : List<string>

View File

@ -1,7 +1,8 @@
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(17,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]':
Types of property 'pop' are incompatible:
Type '() => {}' is not assignable to type '() => number':
Type '{}' is not assignable to type 'number'.
Type '() => string | number' is not assignable to type '() => number':
Type 'string | number' is not assignable to type 'number':
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2322: Type '{}[]' is not assignable to type '[{}]':
Property '0' is missing in type '{}[]'.
@ -27,8 +28,9 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme
~~~~~~~~
!!! error TS2322: Type '[number, string]' is not assignable to type 'number[]':
!!! error TS2322: Types of property 'pop' are incompatible:
!!! error TS2322: Type '() => {}' is not assignable to type '() => number':
!!! error TS2322: Type '{}' is not assignable to type 'number'.
!!! error TS2322: Type '() => string | number' is not assignable to type '() => number':
!!! error TS2322: Type 'string | number' is not assignable to type 'number':
!!! error TS2322: Type 'string' is not assignable to type 'number'.
emptyObjTuple = emptyObjArray;
~~~~~~~~~~~~~
!!! error TS2322: Type '{}[]' is not assignable to type '[{}]':

View File

@ -6,6 +6,6 @@ function method() {
>dictionary : { [x: string]: string; }
><{ [index: string]: string; }>{} : { [x: string]: string; }
>index : string
>{} : { [x: string]: string; }
>{} : { [x: string]: undefined; }
}

View File

@ -54,8 +54,8 @@ var r4 = true ? a : b; // typeof a
>b : { x: number; z?: number; }
var r5 = true ? b : a; // typeof b
>r5 : { x: number; z?: number; }
>true ? b : a : { x: number; z?: number; }
>r5 : { x: number; y?: number; }
>true ? b : a : { x: number; y?: number; }
>b : { x: number; z?: number; }
>a : { x: number; y?: number; }
@ -72,7 +72,7 @@ var r7: (x: Object) => void = true ? (x: number) => { } : (x: Object) => { };
>r7 : (x: Object) => void
>x : Object
>Object : Object
>true ? (x: number) => { } : (x: Object) => { } : (x: Object) => void
>true ? (x: number) => { } : (x: Object) => { } : (x: number) => void
>(x: number) => { } : (x: number) => void
>x : number
>(x: Object) => { } : (x: Object) => void
@ -91,7 +91,7 @@ var r8 = true ? (x: Object) => { } : (x: number) => { }; // returns Object => vo
var r10: Base = true ? derived : derived2; // no error since we use the contextual type in BCT
>r10 : Base
>Base : Base
>true ? derived : derived2 : Base
>true ? derived : derived2 : Derived | Derived2
>derived : Derived
>derived2 : Derived2
@ -112,7 +112,7 @@ function foo5<T, U>(t: T, u: U): Object {
>Object : Object
return true ? t : u; // BCT is Object
>true ? t : u : Object
>true ? t : u : T | U
>t : T
>u : U
}

View File

@ -1,14 +1,9 @@
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(11,10): error TS2367: No best common type exists between 'number' and 'string'.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(12,10): error TS2367: No best common type exists between 'Derived' and 'Derived2'.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(15,12): error TS2367: No best common type exists between 'T' and 'U'.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(18,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(19,12): error TS2367: No best common type exists between 'T' and 'U'.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(22,15): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(22,28): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts(23,12): error TS2367: No best common type exists between 'T' and 'U'.
==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (8 errors) ====
==== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfConditionalExpressions2.ts (3 errors) ====
// conditional expressions return the best common type of the branches plus contextual type (using the first candidate if multiple BCTs exist)
// these are errors
@ -20,24 +15,16 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC
var derived2: Derived2;
var r2 = true ? 1 : '';
~~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'number' and 'string'.
var r9 = true ? derived : derived2;
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'Derived' and 'Derived2'.
function foo<T, U>(t: T, u: U) {
return true ? t : u;
~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'T' and 'U'.
}
function foo2<T extends U, U>(t: T, u: U) { // Error for referencing own type parameter
~~~~~~~~~~~
!!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
return true ? t : u; // Ok because BCT(T, U) = U
~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'T' and 'U'.
}
function foo3<T extends U, U extends V, V>(t: T, u: U) {
@ -46,6 +33,4 @@ tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfC
~~~~~~~~~~~
!!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
return true ? t : u;
~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'T' and 'U'.
}

View File

@ -75,13 +75,13 @@ t4 = [E1.one, E2.two, 20];
>two : E2
var e1 = t1[2]; // {}
>e1 : {}
>t1[2] : {}
>e1 : { (x: number): string; } | { (x: number): number; }
>t1[2] : { (x: number): string; } | { (x: number): number; }
>t1 : [(x: number) => string, (x: number) => number]
var e2 = t2[2]; // {}
>e2 : {}
>t2[2] : {}
>e2 : E1 | E2
>t2[2] : E1 | E2
>t2 : [E1, E2]
var e3 = t3[2]; // any

View File

@ -69,8 +69,8 @@ var e11 = t1[4]; // base
>t1 : [C, base]
var e21 = t2[4]; // {}
>e21 : {}
>t2[4] : {}
>e21 : C | D
>t2[4] : C | D
>t2 : [C, D]
var e31 = t3[4]; // C1
@ -84,7 +84,7 @@ var e41 = t4[2]; // base1
>t4 : [base1, C1]
var e51 = t5[2]; // {}
>e51 : {}
>t5[2] : {}
>e51 : F | C1
>t5[2] : F | C1
>t5 : [C1, F]

View File

@ -1,3 +1,7 @@
tests/cases/conformance/types/tuple/castingTuple.ts(13,23): error TS2353: Neither type '[number, string]' nor type '[number, string, boolean]' is assignable to the other:
Property '2' is missing in type '[number, string]'.
tests/cases/conformance/types/tuple/castingTuple.ts(16,21): error TS2353: Neither type '[C, D]' nor type '[C, D, A]' is assignable to the other:
Property '2' is missing in type '[C, D]'.
tests/cases/conformance/types/tuple/castingTuple.ts(24,10): error TS2353: Neither type '[number, string]' nor type '[number, number]' is assignable to the other:
Types of property '1' are incompatible:
Type 'string' is not assignable to type 'number'.
@ -8,12 +12,13 @@ tests/cases/conformance/types/tuple/castingTuple.ts(25,10): error TS2353: Neithe
tests/cases/conformance/types/tuple/castingTuple.ts(26,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'.
tests/cases/conformance/types/tuple/castingTuple.ts(26,14): error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other:
Types of property 'pop' are incompatible:
Type '() => {}' is not assignable to type '() => number':
Type '{}' is not assignable to type 'number'.
Type '() => string | number' is not assignable to type '() => number':
Type 'string | number' is not assignable to type 'number':
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot find name 't4'.
==== tests/cases/conformance/types/tuple/castingTuple.ts (5 errors) ====
==== tests/cases/conformance/types/tuple/castingTuple.ts (7 errors) ====
interface I { }
class A { a = 10; }
class C implements I { c };
@ -27,9 +32,15 @@ tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot
var numStrTuple: [number, string] = [5, "foo"];
var emptyObjTuple = <[{}, {}]>numStrTuple;
var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[number, string]' nor type '[number, string, boolean]' is assignable to the other:
!!! error TS2353: Property '2' is missing in type '[number, string]'.
var classCDTuple: [C, D] = [new C(), new D()];
var interfaceIITuple = <[I, I]>classCDTuple;
var classCDATuple = <[C, D, A]>classCDTuple;
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[C, D]' nor type '[C, D, A]' is assignable to the other:
!!! error TS2353: Property '2' is missing in type '[C, D]'.
var eleFromCDA1 = classCDATuple[2]; // A
var eleFromCDA2 = classCDATuple[5]; // {}
var t10: [E1, E2] = [E1.one, E2.one];
@ -54,8 +65,9 @@ tests/cases/conformance/types/tuple/castingTuple.ts(27,1): error TS2304: Cannot
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2353: Neither type '[number, string]' nor type 'number[]' is assignable to the other:
!!! error TS2353: Types of property 'pop' are incompatible:
!!! error TS2353: Type '() => {}' is not assignable to type '() => number':
!!! error TS2353: Type '{}' is not assignable to type 'number'.
!!! error TS2353: Type '() => string | number' is not assignable to type '() => number':
!!! error TS2353: Type 'string | number' is not assignable to type 'number':
!!! error TS2353: Type 'string' is not assignable to type 'number'.
t4[2] = 10;
~~
!!! error TS2304: Cannot find name 't4'.

View File

@ -1,10 +1,9 @@
tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2323: Type '{}' is not assignable to type 'boolean'.
tests/cases/compiler/conditionalExpression1.ts(1,19): error TS2367: No best common type exists between 'number' and 'string'.
tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2322: Type 'string | number' is not assignable to type 'boolean':
Type 'string' is not assignable to type 'boolean'.
==== tests/cases/compiler/conditionalExpression1.ts (2 errors) ====
==== tests/cases/compiler/conditionalExpression1.ts (1 errors) ====
var x: boolean = (true ? 1 : ""); // should be an error
~
!!! error TS2323: Type '{}' is not assignable to type 'boolean'.
~~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'number' and 'string'.
!!! error TS2322: Type 'string | number' is not assignable to type 'boolean':
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.

View File

@ -80,7 +80,7 @@ var result4: (t: A) => any = true ? (m) => m.propertyX : (n) => n.propertyA;
>result4 : (t: A) => any
>t : A
>A : A
>true ? (m) => m.propertyX : (n) => n.propertyA : (t: A) => any
>true ? (m) => m.propertyX : (n) => n.propertyA : (m: A) => any
>(m) => m.propertyX : (m: A) => any
>m : A
>m.propertyX : any
@ -144,7 +144,7 @@ var result8: (t: A) => any = true ? (m) => m.propertyA : (n) => n.propertyX;
>result8 : (t: A) => any
>t : A
>A : A
>true ? (m) => m.propertyA : (n) => n.propertyX : (t: A) => any
>true ? (m) => m.propertyA : (n) => n.propertyX : (n: A) => any
>(m) => m.propertyA : (m: A) => number
>m : A
>m.propertyA : number
@ -161,7 +161,7 @@ var result8: (t: A) => any = true ? (m) => m.propertyA : (n) => n.propertyX;
var resultIsX3: X = true ? a : b;
>resultIsX3 : X
>X : X
>true ? a : b : X
>true ? a : b : A | B
>a : A
>b : B
@ -169,7 +169,7 @@ var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
>result10 : (t: X) => any
>t : X
>X : X
>true ? (m) => m.propertyX1 : (n) => n.propertyX2 : (t: X) => any
>true ? (m) => m.propertyX1 : (n) => n.propertyX2 : { (m: X): number; } | { (n: X): string; }
>(m) => m.propertyX1 : (m: X) => number
>m : X
>m.propertyX1 : number
@ -184,5 +184,5 @@ var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
//Expr1 and Expr2 are literals
var result11: any = true ? 1 : 'string';
>result11 : any
>true ? 1 : 'string' : any
>true ? 1 : 'string' : string | number

View File

@ -1,20 +1,21 @@
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(12,1): error TS2367: No best common type exists between 'A' and 'B'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(13,15): error TS2367: No best common type exists between 'A' and 'B'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type '{}' is not assignable to type 'A':
Property 'propertyA' is missing in type '{}'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,18): error TS2366: No best common type exists between 'A', 'A', and 'B'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,5): error TS2322: Type '{}' is not assignable to type 'B':
Property 'propertyB' is missing in type '{}'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(17,18): error TS2366: No best common type exists between 'B', 'A', and 'B'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2323: Type '{}' is not assignable to type '(t: X) => number'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,33): error TS2366: No best common type exists between '(t: X) => number', '(m: X) => number', and '(n: X) => string'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2323: Type '{}' is not assignable to type '(t: X) => string'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,33): error TS2366: No best common type exists between '(t: X) => string', '(m: X) => number', and '(n: X) => string'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,5): error TS2323: Type '{}' is not assignable to type '(t: X) => boolean'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(21,34): error TS2366: No best common type exists between '(t: X) => boolean', '(m: X) => number', and '(n: X) => string'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(15,5): error TS2322: Type 'A | B' is not assignable to type 'A':
Type 'B' is not assignable to type 'A':
Property 'propertyA' is missing in type 'B'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type 'A | B' is not assignable to type 'B':
Type 'A' is not assignable to type 'B':
Property 'propertyB' is missing in type 'A'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(18,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => number':
Type '(n: X) => string' is not assignable to type '(t: X) => number':
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(19,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => string':
Type '(m: X) => number' is not assignable to type '(t: X) => string':
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(20,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => boolean':
Type '(m: X) => number' is not assignable to type '(t: X) => boolean':
Type 'number' is not assignable to type 'boolean'.
==== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts (12 errors) ====
==== tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts (5 errors) ====
//Cond ? Expr1 : Expr2, Expr1 and Expr2 have no identical best common type
class X { propertyX: any; propertyX1: number; propertyX2: string };
class A extends X { propertyA: number };
@ -24,41 +25,34 @@ tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithou
var a: A;
var b: B;
//Expect to have compiler errors
//Be not contextually typed
// No errors anymore, uses union types
true ? a : b;
~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'A' and 'B'.
var result1 = true ? a : b;
~~~~~~~~~~~~
!!! error TS2367: No best common type exists between 'A' and 'B'.
//Be contextually typed and and bct is not identical
//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target
var result2: A = true ? a : b;
~~~~~~~
!!! error TS2322: Type '{}' is not assignable to type 'A':
!!! error TS2322: Property 'propertyA' is missing in type '{}'.
~~~~~~~~~~~~
!!! error TS2366: No best common type exists between 'A', 'A', and 'B'.
!!! error TS2322: Type 'A | B' is not assignable to type 'A':
!!! error TS2322: Type 'B' is not assignable to type 'A':
!!! error TS2322: Property 'propertyA' is missing in type 'B'.
var result3: B = true ? a : b;
~~~~~~~
!!! error TS2322: Type '{}' is not assignable to type 'B':
!!! error TS2322: Property 'propertyB' is missing in type '{}'.
~~~~~~~~~~~~
!!! error TS2366: No best common type exists between 'B', 'A', and 'B'.
!!! error TS2322: Type 'A | B' is not assignable to type 'B':
!!! error TS2322: Type 'A' is not assignable to type 'B':
!!! error TS2322: Property 'propertyB' is missing in type 'A'.
var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
~~~~~~~
!!! error TS2323: Type '{}' is not assignable to type '(t: X) => number'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2366: No best common type exists between '(t: X) => number', '(m: X) => number', and '(n: X) => string'.
!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => number':
!!! error TS2322: Type '(n: X) => string' is not assignable to type '(t: X) => number':
!!! error TS2322: Type 'string' is not assignable to type 'number'.
var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
~~~~~~~
!!! error TS2323: Type '{}' is not assignable to type '(t: X) => string'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2366: No best common type exists between '(t: X) => string', '(m: X) => number', and '(n: X) => string'.
!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => string':
!!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => string':
!!! error TS2322: Type 'number' is not assignable to type 'string'.
var result6: (t: X) => boolean = true ? (m) => m.propertyX1 : (n) => n.propertyX2;
~~~~~~~
!!! error TS2323: Type '{}' is not assignable to type '(t: X) => boolean'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2366: No best common type exists between '(t: X) => boolean', '(m: X) => number', and '(n: X) => string'.
!!! error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => boolean':
!!! error TS2322: Type '(m: X) => number' is not assignable to type '(t: X) => boolean':
!!! error TS2322: Type 'number' is not assignable to type 'boolean'.

View File

@ -8,12 +8,11 @@ var x: X;
var a: A;
var b: B;
//Expect to have compiler errors
//Be not contextually typed
// No errors anymore, uses union types
true ? a : b;
var result1 = true ? a : b;
//Be contextually typed and and bct is not identical
//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target
var result2: A = true ? a : b;
var result3: B = true ? a : b;
@ -54,11 +53,10 @@ var B = (function (_super) {
var x;
var a;
var b;
//Expect to have compiler errors
//Be not contextually typed
// No errors anymore, uses union types
true ? a : b;
var result1 = true ? a : b;
//Be contextually typed and and bct is not identical
//Be contextually typed and and bct is not identical, results in errors that union type is not assignable to target
var result2 = true ? a : b;
var result3 = true ? a : b;
var result4 = true ? function (m) { return m.propertyX1; } : function (n) { return n.propertyX2; };

View File

@ -26,18 +26,18 @@ interface Transform3D {
var style: IBookStyle = {
>style : IBookStyle
>IBookStyle : IBookStyle
>{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => NamedTransform[]; }
>{ initialLeftPageTransforms: (width: number) => { return [ {'ry': null } ]; }} : { initialLeftPageTransforms: (width: number) => { [x: string]: any; 'ry': any; }[]; }
initialLeftPageTransforms: (width: number) => {
>initialLeftPageTransforms : (width: number) => NamedTransform[]
>(width: number) => { return [ {'ry': null } ]; } : (width: number) => NamedTransform[]
>initialLeftPageTransforms : (width: number) => { [x: string]: any; 'ry': any; }[]
>(width: number) => { return [ {'ry': null } ]; } : (width: number) => { [x: string]: any; 'ry': any; }[]
>width : number
return [
>[ {'ry': null } ] : NamedTransform[]
>[ {'ry': null } ] : { [x: string]: null; 'ry': null; }[]
{'ry': null }
>{'ry': null } : { [x: string]: Transform3D; 'ry': null; }
>{'ry': null } : { [x: string]: null; 'ry': null; }
];
}

View File

@ -1,3 +1,10 @@
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(3,5): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]':
Types of property 'pop' are incompatible:
Type '() => string | number | boolean' is not assignable to type '() => string | number':
Type 'string | number | boolean' is not assignable to type 'string | number':
Type 'boolean' is not assignable to type 'string | number':
Type 'boolean' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(8,1): error TS2323: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(11,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]':
Types of property '0' are incompatible:
Type '{}' is not assignable to type '{ a: string; }':
@ -6,19 +13,29 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(12,1): error TS23
Property '2' is missing in type '[number, string]'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(13,5): error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]':
Types of property 'pop' are incompatible:
Type '() => {}' is not assignable to type '() => string':
Type '{}' is not assignable to type 'string'.
Type '() => string | number' is not assignable to type '() => string':
Type 'string | number' is not assignable to type 'string':
Type 'number' is not assignable to type 'string'.
==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (3 errors) ====
==== tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts (5 errors) ====
// no error
var numStrTuple: [number, string] = [5, "hello"];
var numStrTuple2: [number, string] = [5, "foo", true];
~~~~~~~~~~~~
!!! error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]':
!!! error TS2322: Types of property 'pop' are incompatible:
!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number':
!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number':
!!! error TS2322: Type 'boolean' is not assignable to type 'string | number':
!!! error TS2322: Type 'boolean' is not assignable to type 'number'.
var numStrBoolTuple: [number, string, boolean] = [5, "foo", true];
var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5];
var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]];
numStrTuple = numStrTuple2;
numStrTuple = numStrBoolTuple;
~~~~~~~~~~~
!!! error TS2323: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
// error
objNumTuple = [ {}, 5];
@ -35,6 +52,7 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(13,5): error TS23
~~~~~~~~~~~
!!! error TS2322: Type '[string, string, number]' is not assignable to type '[string, string]':
!!! error TS2322: Types of property 'pop' are incompatible:
!!! error TS2322: Type '() => {}' is not assignable to type '() => string':
!!! error TS2322: Type '{}' is not assignable to type 'string'.
!!! error TS2322: Type '() => string | number' is not assignable to type '() => string':
!!! error TS2322: Type 'string | number' is not assignable to type 'string':
!!! error TS2322: Type 'number' is not assignable to type 'string'.

View File

@ -1,11 +1,13 @@
tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '{}[]' is not assignable to type '{ id: number; }[]':
Type '{}' is not assignable to type '{ id: number; }':
Property 'id' is missing in type '{}'.
tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type 'Array<number | { id: number; }>' is not assignable to type '{ id: number; }[]':
Type 'number | { id: number; }' is not assignable to type '{ id: number; }':
Type 'number' is not assignable to type '{ id: number; }':
Property 'id' is missing in type 'Number'.
==== tests/cases/compiler/contextualTyping21.ts (1 errors) ====
var foo:{id:number;}[] = [{id:1}]; foo = [{id:1}, 1];
~~~
!!! error TS2322: Type '{}[]' is not assignable to type '{ id: number; }[]':
!!! error TS2322: Type '{}' is not assignable to type '{ id: number; }':
!!! error TS2322: Property 'id' is missing in type '{}'.
!!! error TS2322: Type 'Array<number | { id: number; }>' is not assignable to type '{ id: number; }[]':
!!! error TS2322: Type 'number | { id: number; }' is not assignable to type '{ id: number; }':
!!! error TS2322: Type 'number' is not assignable to type '{ id: number; }':
!!! error TS2322: Property 'id' is missing in type 'Number'.

View File

@ -1,9 +1,11 @@
tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'.
Type '{}' is not assignable to type 'number'.
tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type 'Array<string | number>' is not assignable to parameter of type 'number[]'.
Type 'string | number' is not assignable to type 'number':
Type 'string' is not assignable to type 'number'.
==== tests/cases/compiler/contextualTyping30.ts (1 errors) ====
function foo(param:number[]){}; foo([1, "a"]);
~~~~~~~~
!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type 'number[]'.
!!! error TS2345: Type '{}' is not assignable to type 'number'.
!!! error TS2345: Argument of type 'Array<string | number>' is not assignable to parameter of type 'number[]'.
!!! error TS2345: Type 'string | number' is not assignable to type 'number':
!!! error TS2345: Type 'string' is not assignable to type 'number'.

View File

@ -5,7 +5,7 @@ function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){ret
>i : number
>foo([function(){return 1;}, function(){return 4}]) : void
>foo : (param: { (): number; (i: number): number; }[]) => void
>[function(){return 1;}, function(){return 4}] : { (): number; (i: number): number; }[]
>[function(){return 1;}, function(){return 4}] : { (): number; }[]
>function(){return 1;} : () => number
>function(){return 4} : () => number

View File

@ -1,9 +1,11 @@
tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'.
Type '{}' is not assignable to type '{ (): number; (i: number): number; }'.
tests/cases/compiler/contextualTyping33.ts(1,66): error TS2345: Argument of type 'Array<{ (): number; } | { (): string; }>' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'.
Type '{ (): number; } | { (): string; }' is not assignable to type '{ (): number; (i: number): number; }':
Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'.
==== tests/cases/compiler/contextualTyping33.ts (1 errors) ====
function foo(param: {():number; (i:number):number; }[]) { }; foo([function(){return 1;}, function(){return "foo"}]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{}[]' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'.
!!! error TS2345: Type '{}' is not assignable to type '{ (): number; (i: number): number; }'.
!!! error TS2345: Argument of type 'Array<{ (): number; } | { (): string; }>' is not assignable to parameter of type '{ (): number; (i: number): number; }[]'.
!!! error TS2345: Type '{ (): number; } | { (): string; }' is not assignable to type '{ (): number; (i: number): number; }':
!!! error TS2345: Type '() => string' is not assignable to type '{ (): number; (i: number): number; }'.

View File

@ -1,7 +1,8 @@
tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '{}[]' is not assignable to type 'I':
tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type 'Array<number | Date>' is not assignable to type 'I':
Index signatures are incompatible:
Type '{}' is not assignable to type 'Date':
Property 'toDateString' is missing in type '{}'.
Type 'number | Date' is not assignable to type 'Date':
Type 'number' is not assignable to type 'Date':
Property 'toDateString' is missing in type 'Number'.
==== tests/cases/compiler/contextualTypingOfArrayLiterals1.ts (1 errors) ====
@ -11,10 +12,11 @@ tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Typ
var x3: I = [new Date(), 1];
~~
!!! error TS2322: Type '{}[]' is not assignable to type 'I':
!!! error TS2322: Type 'Array<number | Date>' is not assignable to type 'I':
!!! error TS2322: Index signatures are incompatible:
!!! error TS2322: Type '{}' is not assignable to type 'Date':
!!! error TS2322: Property 'toDateString' is missing in type '{}'.
!!! error TS2322: Type 'number | Date' is not assignable to type 'Date':
!!! error TS2322: Type 'number' is not assignable to type 'Date':
!!! error TS2322: Property 'toDateString' is missing in type 'Number'.
var r2 = x3[1];
r2.getDate();

View File

@ -2,7 +2,7 @@
var x: (a: number) => void = true ? (a) => a.toExponential() : (b) => b.toFixed();
>x : (a: number) => void
>a : number
>true ? (a) => a.toExponential() : (b) => b.toFixed() : (a: number) => void
>true ? (a) => a.toExponential() : (b) => b.toFixed() : (a: number) => string
>(a) => a.toExponential() : (a: number) => string
>a : number
>a.toExponential() : string
@ -41,7 +41,7 @@ var x2: (a: A) => void = true ? (a) => a.foo : (b) => b.foo;
>x2 : (a: A) => void
>a : A
>A : A
>true ? (a) => a.foo : (b) => b.foo : (a: A) => void
>true ? (a) => a.foo : (b) => b.foo : (a: A) => number
>(a) => a.foo : (a: A) => number
>a : A
>a.foo : number

View File

@ -1,8 +1,11 @@
tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2323: Type '{}' is not assignable to type '(a: A) => void'.
tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,26): error TS2366: No best common type exists between '(a: A) => void', '(a: C) => number', and '(b: number) => void'.
tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,5): error TS2322: Type '{ (a: C): number; } | { (b: number): void; }' is not assignable to type '(a: A) => void':
Type '(b: number) => void' is not assignable to type '(a: A) => void':
Types of parameters 'b' and 'a' are incompatible:
Type 'number' is not assignable to type 'A':
Property 'foo' is missing in type 'Number'.
==== tests/cases/compiler/contextualTypingOfConditionalExpression2.ts (2 errors) ====
==== tests/cases/compiler/contextualTypingOfConditionalExpression2.ts (1 errors) ====
class A {
foo: number;
}
@ -15,7 +18,9 @@ tests/cases/compiler/contextualTypingOfConditionalExpression2.ts(11,26): error T
var x2: (a: A) => void = true ? (a: C) => a.foo : (b: number) => { };
~~
!!! error TS2323: Type '{}' is not assignable to type '(a: A) => void'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2366: No best common type exists between '(a: A) => void', '(a: C) => number', and '(b: number) => void'.
!!! error TS2322: Type '{ (a: C): number; } | { (b: number): void; }' is not assignable to type '(a: A) => void':
!!! error TS2322: Type '(b: number) => void' is not assignable to type '(a: A) => void':
!!! error TS2322: Types of parameters 'b' and 'a' are incompatible:
!!! error TS2322: Type 'number' is not assignable to type 'A':
!!! error TS2322: Property 'foo' is missing in type 'Number'.

View File

@ -1,9 +1,12 @@
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(2,22): error TS2339: Property 'foo' does not exist on type 'string'.
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,10): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (1 errors) ====
==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (2 errors) ====
var f10: <T>(x: T, b: () => (a: T) => void, y: T) => T;
f10('', () => a => a.foo, ''); // a is string, fixed by first parameter
f10('', () => a => a.foo, ''); // a is string
~~~
!!! error TS2339: Property 'foo' does not exist on type 'string'.
var r9 = f10('', () => (a => a.foo), 1); // now a should be any
var r9 = f10('', () => (a => a.foo), 1); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.

View File

@ -1,9 +1,9 @@
//// [contextualTypingWithFixedTypeParameters1.ts]
var f10: <T>(x: T, b: () => (a: T) => void, y: T) => T;
f10('', () => a => a.foo, ''); // a is string, fixed by first parameter
var r9 = f10('', () => (a => a.foo), 1); // now a should be any
f10('', () => a => a.foo, ''); // a is string
var r9 = f10('', () => (a => a.foo), 1); // error
//// [contextualTypingWithFixedTypeParameters1.js]
var f10;
f10('', function () { return function (a) { return a.foo; }; }, ''); // a is string, fixed by first parameter
var r9 = f10('', function () { return (function (a) { return a.foo; }); }, 1); // now a should be any
f10('', function () { return function (a) { return a.foo; }; }, ''); // a is string
var r9 = f10('', function () { return (function (a) { return a.foo; }); }, 1); // error

View File

@ -3,7 +3,7 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 };
>v : { a: (_: string) => number; }
>a : (_: string) => number
>_ : string
>{ a: s => s.length } || { a: s => 1 } : { a: (_: string) => number; }
>{ a: s => s.length } || { a: s => 1 } : { a: (s: string) => number; }
>{ a: s => s.length } : { a: (s: string) => number; }
>a : (s: string) => number
>s => s.length : (s: string) => number
@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 };
>s : string
var v2 = (s: string) => s.length || function (s) { s.length };
>v2 : (s: string) => {}
>(s: string) => s.length || function (s) { s.length } : (s: string) => {}
>v2 : (s: string) => number | { (s: any): void; }
>(s: string) => s.length || function (s) { s.length } : (s: string) => number | { (s: any): void; }
>s : string
>s.length || function (s) { s.length } : {}
>s.length || function (s) { s.length } : number | { (s: any): void; }
>s.length : number
>s : string
>length : number
@ -31,10 +31,10 @@ var v2 = (s: string) => s.length || function (s) { s.length };
>length : any
var v3 = (s: string) => s.length || function (s: number) { return 1 };
>v3 : (s: string) => {}
>(s: string) => s.length || function (s: number) { return 1 } : (s: string) => {}
>v3 : (s: string) => number | { (s: number): number; }
>(s: string) => s.length || function (s: number) { return 1 } : (s: string) => number | { (s: number): number; }
>s : string
>s.length || function (s: number) { return 1 } : {}
>s.length || function (s: number) { return 1 } : number | { (s: number): number; }
>s.length : number
>s : string
>length : number
@ -42,10 +42,10 @@ var v3 = (s: string) => s.length || function (s: number) { return 1 };
>s : number
var v4 = (s: number) => 1 || function (s: string) { return s.length };
>v4 : (s: number) => {}
>(s: number) => 1 || function (s: string) { return s.length } : (s: number) => {}
>v4 : (s: number) => number | { (s: string): number; }
>(s: number) => 1 || function (s: string) { return s.length } : (s: number) => number | { (s: string): number; }
>s : number
>1 || function (s: string) { return s.length } : {}
>1 || function (s: string) { return s.length } : number | { (s: string): number; }
>function (s: string) { return s.length } : (s: string) => number
>s : string
>s.length : number

View File

@ -3,7 +3,7 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 };
>v : { a: (_: string) => number; }
>a : (_: string) => number
>_ : string
>{ a: s => s.length } || { a: s => 1 } : { a: (_: string) => number; }
>{ a: s => s.length } || { a: s => 1 } : { a: (s: string) => number; }
>{ a: s => s.length } : { a: (s: string) => number; }
>a : (s: string) => number
>s => s.length : (s: string) => number
@ -17,10 +17,10 @@ var v: { a: (_: string) => number } = { a: s => s.length } || { a: s => 1 };
>s : string
var v2 = (s: string) => s.length || function (s) { s.aaa };
>v2 : (s: string) => {}
>(s: string) => s.length || function (s) { s.aaa } : (s: string) => {}
>v2 : (s: string) => number | { (s: any): void; }
>(s: string) => s.length || function (s) { s.aaa } : (s: string) => number | { (s: any): void; }
>s : string
>s.length || function (s) { s.aaa } : {}
>s.length || function (s) { s.aaa } : number | { (s: any): void; }
>s.length : number
>s : string
>length : number

View File

@ -131,11 +131,11 @@ module templa.dom.mvc.composite {
>super : typeof AbstractElementController
this._controllers = [];
>this._controllers = [] : templa.mvc.IController<templa.mvc.IModel>[]
>this._controllers = [] : undefined[]
>this._controllers : templa.mvc.IController<templa.mvc.IModel>[]
>this : AbstractCompositeElementController<ModelType>
>_controllers : templa.mvc.IController<templa.mvc.IModel>[]
>[] : templa.mvc.IController<templa.mvc.IModel>[]
>[] : undefined[]
}
}
}

View File

@ -9,7 +9,7 @@ var ANY1;
var ANY2: any[] = ["", ""];
>ANY2 : any[]
>["", ""] : any[]
>["", ""] : string[]
var obj = {x:1,y:null};
>obj : { x: number; y: any; }

View File

@ -1,31 +1,27 @@
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(4,6): error TS2339: Property 'length' does not exist on type '{}'.
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(10,6): error TS2339: Property 'length' does not exist on type 'Object'.
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(18,27): error TS2339: Property 'length' does not exist on type '{}'.
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(2,6): error TS2339: Property 'length' does not exist on type '{}'.
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(5,6): error TS2339: Property 'length' does not exist on type 'Object'.
tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts(8,14): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts (3 errors) ====
var obj1: {};
obj1.length;
~~~~~~
!!! error TS2339: Property 'length' does not exist on type '{}'.
var obj2: Object;
obj2.length;
~~~~~~
!!! error TS2339: Property 'length' does not exist on type 'Object'.
function concat<T>(x: T, y: T): T { return null; }
var result = concat(1, ""); // error
~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var elementCount = result.length;
var result = concat(1, "");
function concat2<T, U>(x: T, y: U) { return null; }
var result2 = concat2(1, ""); // result2 will be number|string
var elementCount2 = result.length;
var elementCount = result.length; // would like to get an error by now
~~~~~~
!!! error TS2339: Property 'length' does not exist on type '{}'.

View File

@ -1,22 +1,18 @@
//// [defaultBestCommonTypesHaveDecls.ts]
var obj1: {};
obj1.length;
var obj2: Object;
obj2.length;
function concat<T>(x: T, y: T): T { return null; }
var result = concat(1, ""); // error
var elementCount = result.length;
var result = concat(1, "");
function concat2<T, U>(x: T, y: U) { return null; }
var result2 = concat2(1, ""); // result2 will be number|string
var elementCount2 = result.length;
var elementCount = result.length; // would like to get an error by now
//// [defaultBestCommonTypesHaveDecls.js]
@ -27,5 +23,10 @@ obj2.length;
function concat(x, y) {
return null;
}
var result = concat(1, "");
var elementCount = result.length; // would like to get an error by now
var result = concat(1, ""); // error
var elementCount = result.length;
function concat2(x, y) {
return null;
}
var result2 = concat2(1, ""); // result2 will be number|string
var elementCount2 = result.length;

View File

@ -49,7 +49,7 @@ b = d2;
var r: Base[] = [d1, d2];
>r : Base[]
>Base : Base
>[d1, d2] : Base[]
>[d1, d2] : Array<Derived | Derived2>
>d1 : Derived
>d2 : Derived2

View File

@ -21,7 +21,7 @@ interface IIntervalTreeNode {
var test: IIntervalTreeNode[] = [{ interval: { begin: 0 }, children: null }]; // was error here because best common type is {}
>test : IIntervalTreeNode[]
>IIntervalTreeNode : IIntervalTreeNode
>[{ interval: { begin: 0 }, children: null }] : IIntervalTreeNode[]
>[{ interval: { begin: 0 }, children: null }] : { interval: { begin: number; }; children: null; }[]
>{ interval: { begin: 0 }, children: null } : { interval: { begin: number; }; children: null; }
>interval : { begin: number; }
>{ begin: 0 } : { begin: number; }

View File

@ -157,8 +157,8 @@ enum E9 {
// (refer to .js to validate)
// Enum constant members are propagated
var doNotPropagate = [
>doNotPropagate : {}[]
>[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : {}[]
>doNotPropagate : Array<E3 | E4 | E7 | E8>
>[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : Array<E3 | E4 | E7 | E8>
E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z
>E8.B : E8
@ -183,8 +183,8 @@ var doNotPropagate = [
];
// Enum computed members are not propagated
var doPropagate = [
>doPropagate : {}[]
>[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : {}[]
>doPropagate : Array<E5 | E6 | E9>
>[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : Array<E5 | E6 | E9>
E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C
>E9.A : E9

View File

@ -25,7 +25,7 @@ var moduleMap: { [key: string]: IHasVisualizationModel } = {
>moduleMap : { [x: string]: IHasVisualizationModel; }
>key : string
>IHasVisualizationModel : IHasVisualizationModel
>{ "moduleA": moduleA, "moduleB": moduleB} : { [x: string]: IHasVisualizationModel; "moduleA": typeof moduleA; "moduleB": typeof moduleB; }
>{ "moduleA": moduleA, "moduleB": moduleB} : { [x: string]: typeof moduleA; "moduleA": typeof moduleA; "moduleB": typeof moduleB; }
"moduleA": moduleA,
>moduleA : typeof moduleA

View File

@ -0,0 +1,8 @@
tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts(2,1): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts (1 errors) ====
function bar<T>(item1: T, item2: T) { }
bar(1, ""); // Should be ok
~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.

View File

@ -1,13 +0,0 @@
=== tests/cases/compiler/fixTypeParameterInSignatureWithRestParameters.ts ===
function bar<T>(item1: T, item2: T) { }
>bar : <T>(item1: T, item2: T) => void
>T : T
>item1 : T
>T : T
>item2 : T
>T : T
bar(1, ""); // Should be ok
>bar(1, "") : void
>bar : <T>(item1: T, item2: T) => void

View File

@ -7,7 +7,7 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec
tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(40,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'.
tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(43,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'.
tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(46,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'.
tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(47,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'.
tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(47,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array<C | D<string>>'.
tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(50,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D<string>[]', but here has type 'D<number>[]'.
tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts(53,10): error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'.
@ -79,7 +79,7 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'.
for( var arr = [new C(), new C2(), new D<string>()];;){}
~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '{}[]'.
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'Array<C | D<string>>'.
for(var arr2 = [new D<string>()];;){}
for( var arr2 = new Array<D<number>>();;){}

View File

@ -109,11 +109,11 @@ for (var a = ['a', 'b']; ;) { }
for (var a = <string[]>[]; ;) { }
>a : string[]
><string[]>[] : string[]
>[] : string[]
>[] : undefined[]
for (var a: string[] = []; ;) { }
>a : string[]
>[] : string[]
>[] : undefined[]
for (var a = new Array<string>(); ;) { }
>a : string[]

View File

@ -1,7 +1,7 @@
=== tests/cases/compiler/functionCall3.ts ===
function foo():any[]{return [1];}
>foo : () => any[]
>[1] : any[]
>[1] : number[]
var x = foo();
>x : any[]

View File

@ -19,7 +19,7 @@ var x = foo([{a:'s'}]);
>x : number
>foo([{a:'s'}]) : number
>foo : { (bar: { a: number; }[]): string; (bar: { a: any; }[]): number; }
>[{a:'s'}] : { a: any; }[]
>[{a:'s'}] : { a: string; }[]
>{a:'s'} : { a: string; }
>a : string

View File

@ -5,7 +5,7 @@ class EventBase {
private _listeners: { (...args: any[]): void; }[] = [];
>_listeners : { (...args: any[]): void; }[]
>args : any[]
>[] : { (...args: any[]): void; }[]
>[] : undefined[]
add(listener: (...args: any[]) => void): void {
>add : (listener: (...args: any[]) => void) => void

View File

@ -21,7 +21,7 @@ module test {
var ys: U[] = [];
>ys : U[]
>U : U
>[] : U[]
>[] : undefined[]
}
}

File diff suppressed because it is too large Load Diff

View File

@ -49,7 +49,7 @@ _.all([true, 1, null, 'yes'], _.identity);
>_.all : <T>(list: T[], iterator?: Underscore.Iterator<T, boolean>, context?: any) => boolean
>_ : Underscore.Static
>all : <T>(list: T[], iterator?: Underscore.Iterator<T, boolean>, context?: any) => boolean
>[true, 1, null, 'yes'] : {}[]
>[true, 1, null, 'yes'] : Array<string | number | boolean>
>_.identity : <T>(value: T) => T
>_ : Underscore.Static
>identity : <T>(value: T) => T

View File

@ -16,6 +16,6 @@ function map<U>() {
var ys: U[] = [];
>ys : U[]
>U : U
>[] : U[]
>[] : undefined[]
}

View File

@ -14,11 +14,11 @@ class BaseCollection2<TItem extends CollectionItem2> {
constructor() {
this._itemsByKey = {};
>this._itemsByKey = {} : { [x: string]: TItem; }
>this._itemsByKey = {} : { [x: string]: undefined; }
>this._itemsByKey : { [x: string]: TItem; }
>this : BaseCollection2<TItem>
>_itemsByKey : { [x: string]: TItem; }
>{} : { [x: string]: TItem; }
>{} : { [x: string]: undefined; }
}
}

View File

@ -25,36 +25,36 @@ var ra = foo<any[]>([1, 2]); // any[]
>ra : any[]
>foo<any[]>([1, 2]) : any[]
>foo : <T>(t: T) => T
>[1, 2] : any[]
>[1, 2] : number[]
var r2 = foo([]); // any[]
>r2 : any[]
>foo([]) : any[]
>foo : <T>(t: T) => T
>[] : any[]
>[] : undefined[]
var r3 = foo<number[]>([]); // number[]
>r3 : number[]
>foo<number[]>([]) : number[]
>foo : <T>(t: T) => T
>[] : number[]
>[] : undefined[]
var r4 = foo([1, '']); // {}[]
>r4 : {}[]
>foo([1, '']) : {}[]
>r4 : Array<string | number>
>foo([1, '']) : Array<string | number>
>foo : <T>(t: T) => T
>[1, ''] : {}[]
>[1, ''] : Array<string | number>
var r5 = foo<any[]>([1, '']); // any[]
>r5 : any[]
>foo<any[]>([1, '']) : any[]
>foo : <T>(t: T) => T
>[1, ''] : any[]
>[1, ''] : Array<string | number>
var r6 = foo<Object[]>([1, '']); // Object[]
>r6 : Object[]
>foo<Object[]>([1, '']) : Object[]
>foo : <T>(t: T) => T
>Object : Object
>[1, ''] : Object[]
>[1, ''] : Array<string | number>

View File

@ -0,0 +1,58 @@
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(26,18): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(30,15): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(33,15): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(34,16): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts(35,23): error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'.
Type 'string' is not assignable to type 'number'.
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts (5 errors) ====
// Generic functions used as arguments for function typed parameters are not used to make inferences from
// Using function arguments, no errors expected
function foo<T>(x: (a: T) => T) {
return x(null);
}
var r = foo(<U>(x: U) => ''); // {}
var r2 = foo<string>(<U>(x: U) => ''); // string
var r3 = foo(x => ''); // {}
function foo2<T, U>(x: T, cb: (a: T) => U) {
return cb(x);
}
var r4 = foo2(1, function <Z>(a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions
var r5 = foo2(1, (a) => ''); // string
var r6 = foo2<string, number>('', <Z>(a: Z) => 1);
function foo3<T, U>(x: T, cb: (a: T) => U, y: U) {
return cb(x);
}
var r7 = foo3(1, <Z>(a: Z) => '', ''); // string
var r8 = foo3(1, function (a) { return '' }, 1); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'.
!!! error TS2345: Type 'string' is not assignable to type 'number'.
var r9 = foo3<number, string>(1, (a) => '', ''); // string
function other<T, U>(t: T, u: U) {
var r10 = foo2(1, (x: T) => ''); // error
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var r10 = foo2(1, (x) => ''); // string
var r11 = foo3(1, (x: T) => '', ''); // error
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var r11b = foo3(1, (x: T) => '', 1); // error
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var r12 = foo3(1, function (a) { return '' }, 1); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '(a: number) => string' is not assignable to parameter of type '(a: number) => number'.
!!! error TS2345: Type 'string' is not assignable to type 'number'.
}

View File

@ -24,16 +24,16 @@ function foo3<T, U>(x: T, cb: (a: T) => U, y: U) {
var r7 = foo3(1, <Z>(a: Z) => '', ''); // string
var r8 = foo3(1, function (a) { return '' }, 1); // {}
var r8 = foo3(1, function (a) { return '' }, 1); // error
var r9 = foo3<number, string>(1, (a) => '', ''); // string
function other<T, U>(t: T, u: U) {
var r10 = foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made
var r10 = foo2(1, (x: T) => ''); // error
var r10 = foo2(1, (x) => ''); // string
var r11 = foo3(1, (x: T) => '', ''); // string
var r11b = foo3(1, (x: T) => '', 1); // {}
var r12 = foo3(1, function (a) { return '' }, 1); // {}
var r11 = foo3(1, (x: T) => '', ''); // error
var r11b = foo3(1, (x: T) => '', 1); // error
var r12 = foo3(1, function (a) { return '' }, 1); // error
}
//// [genericCallWithFunctionTypedArguments.js]
@ -59,14 +59,14 @@ function foo3(x, cb, y) {
var r7 = foo3(1, function (a) { return ''; }, ''); // string
var r8 = foo3(1, function (a) {
return '';
}, 1); // {}
}, 1); // error
var r9 = foo3(1, function (a) { return ''; }, ''); // string
function other(t, u) {
var r10 = foo2(1, function (x) { return ''; }); // string, non-generic signature allows inferences to be made
var r10 = foo2(1, function (x) { return ''; }); // error
var r10 = foo2(1, function (x) { return ''; }); // string
var r11 = foo3(1, function (x) { return ''; }, ''); // string
var r11b = foo3(1, function (x) { return ''; }, 1); // {}
var r11 = foo3(1, function (x) { return ''; }, ''); // error
var r11b = foo3(1, function (x) { return ''; }, 1); // error
var r12 = foo3(1, function (a) {
return '';
}, 1); // {}
}, 1); // error
}

View File

@ -1,173 +0,0 @@
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts ===
// Generic functions used as arguments for function typed parameters are not used to make inferences from
// Using function arguments, no errors expected
function foo<T>(x: (a: T) => T) {
>foo : <T>(x: (a: T) => T) => T
>T : T
>x : (a: T) => T
>a : T
>T : T
>T : T
return x(null);
>x(null) : T
>x : (a: T) => T
}
var r = foo(<U>(x: U) => ''); // {}
>r : {}
>foo(<U>(x: U) => '') : {}
>foo : <T>(x: (a: T) => T) => T
><U>(x: U) => '' : <U>(x: U) => string
>U : U
>x : U
>U : U
var r2 = foo<string>(<U>(x: U) => ''); // string
>r2 : string
>foo<string>(<U>(x: U) => '') : string
>foo : <T>(x: (a: T) => T) => T
><U>(x: U) => '' : <U>(x: U) => string
>U : U
>x : U
>U : U
var r3 = foo(x => ''); // {}
>r3 : {}
>foo(x => '') : {}
>foo : <T>(x: (a: T) => T) => T
>x => '' : (x: {}) => string
>x : {}
function foo2<T, U>(x: T, cb: (a: T) => U) {
>foo2 : <T, U>(x: T, cb: (a: T) => U) => U
>T : T
>U : U
>x : T
>T : T
>cb : (a: T) => U
>a : T
>T : T
>U : U
return cb(x);
>cb(x) : U
>cb : (a: T) => U
>x : T
}
var r4 = foo2(1, function <Z>(a: Z) { return '' }); // string, contextual signature instantiation is applied to generic functions
>r4 : string
>foo2(1, function <Z>(a: Z) { return '' }) : string
>foo2 : <T, U>(x: T, cb: (a: T) => U) => U
>function <Z>(a: Z) { return '' } : <Z>(a: Z) => string
>Z : Z
>a : Z
>Z : Z
var r5 = foo2(1, (a) => ''); // string
>r5 : string
>foo2(1, (a) => '') : string
>foo2 : <T, U>(x: T, cb: (a: T) => U) => U
>(a) => '' : (a: number) => string
>a : number
var r6 = foo2<string, number>('', <Z>(a: Z) => 1);
>r6 : number
>foo2<string, number>('', <Z>(a: Z) => 1) : number
>foo2 : <T, U>(x: T, cb: (a: T) => U) => U
><Z>(a: Z) => 1 : <Z>(a: Z) => number
>Z : Z
>a : Z
>Z : Z
function foo3<T, U>(x: T, cb: (a: T) => U, y: U) {
>foo3 : <T, U>(x: T, cb: (a: T) => U, y: U) => U
>T : T
>U : U
>x : T
>T : T
>cb : (a: T) => U
>a : T
>T : T
>U : U
>y : U
>U : U
return cb(x);
>cb(x) : U
>cb : (a: T) => U
>x : T
}
var r7 = foo3(1, <Z>(a: Z) => '', ''); // string
>r7 : string
>foo3(1, <Z>(a: Z) => '', '') : string
>foo3 : <T, U>(x: T, cb: (a: T) => U, y: U) => U
><Z>(a: Z) => '' : <Z>(a: Z) => string
>Z : Z
>a : Z
>Z : Z
var r8 = foo3(1, function (a) { return '' }, 1); // {}
>r8 : {}
>foo3(1, function (a) { return '' }, 1) : {}
>foo3 : <T, U>(x: T, cb: (a: T) => U, y: U) => U
>function (a) { return '' } : (a: number) => string
>a : number
var r9 = foo3<number, string>(1, (a) => '', ''); // string
>r9 : string
>foo3<number, string>(1, (a) => '', '') : string
>foo3 : <T, U>(x: T, cb: (a: T) => U, y: U) => U
>(a) => '' : (a: number) => string
>a : number
function other<T, U>(t: T, u: U) {
>other : <T, U>(t: T, u: U) => void
>T : T
>U : U
>t : T
>T : T
>u : U
>U : U
var r10 = foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made
>r10 : string
>foo2(1, (x: T) => '') : string
>foo2 : <T, U>(x: T, cb: (a: T) => U) => U
>(x: T) => '' : (x: T) => string
>x : T
>T : T
var r10 = foo2(1, (x) => ''); // string
>r10 : string
>foo2(1, (x) => '') : string
>foo2 : <T, U>(x: T, cb: (a: T) => U) => U
>(x) => '' : (x: number) => string
>x : number
var r11 = foo3(1, (x: T) => '', ''); // string
>r11 : string
>foo3(1, (x: T) => '', '') : string
>foo3 : <T, U>(x: T, cb: (a: T) => U, y: U) => U
>(x: T) => '' : (x: T) => string
>x : T
>T : T
var r11b = foo3(1, (x: T) => '', 1); // {}
>r11b : {}
>foo3(1, (x: T) => '', 1) : {}
>foo3 : <T, U>(x: T, cb: (a: T) => U, y: U) => U
>(x: T) => '' : (x: T) => string
>x : T
>T : T
var r12 = foo3(1, function (a) { return '' }, 1); // {}
>r12 : {}
>foo3(1, function (a) { return '' }, 1) : {}
>foo3 : <T, U>(x: T, cb: (a: T) => U, y: U) => U
>function (a) { return '' } : (a: number) => string
>a : number
}

View File

@ -0,0 +1,50 @@
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts(29,10): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts(40,10): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts (2 errors) ====
// Generic functions used as arguments for function typed parameters are not used to make inferences from
// Using construct signature arguments, no errors expected
function foo<T>(x: new(a: T) => T) {
return new x(null);
}
interface I {
new <T>(x: T): T;
}
interface I2<T> {
new (x: T): T;
}
var i: I;
var i2: I2<string>;
var a: {
new <T>(x: T): T;
}
var r = foo(i); // any
var r2 = foo<string>(i); // string
var r3 = foo(i2); // string
var r3b = foo(a); // any
function foo2<T, U>(x: T, cb: new(a: T) => U) {
return new cb(x);
}
var r4 = foo2(1, i2); // error
~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var r4b = foo2(1, a); // any
var r5 = foo2(1, i); // any
var r6 = foo2<string, string>('', i2); // string
function foo3<T, U>(x: T, cb: new(a: T) => U, y: U) {
return new cb(x);
}
var r7 = foo3(null, i, ''); // any
var r7b = foo3(null, a, ''); // any
var r8 = foo3(1, i2, 1); // error
~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var r9 = foo3<string, string>('', i2, ''); // string

View File

@ -27,7 +27,7 @@ function foo2<T, U>(x: T, cb: new(a: T) => U) {
return new cb(x);
}
var r4 = foo2(1, i2); // string, instantiated generic
var r4 = foo2(1, i2); // error
var r4b = foo2(1, a); // any
var r5 = foo2(1, i); // any
var r6 = foo2<string, string>('', i2); // string
@ -38,7 +38,7 @@ function foo3<T, U>(x: T, cb: new(a: T) => U, y: U) {
var r7 = foo3(null, i, ''); // any
var r7b = foo3(null, a, ''); // any
var r8 = foo3(1, i2, 1); // {}
var r8 = foo3(1, i2, 1); // error
var r9 = foo3<string, string>('', i2, ''); // string
//// [genericCallWithFunctionTypedArguments2.js]
@ -57,7 +57,7 @@ var r3b = foo(a); // any
function foo2(x, cb) {
return new cb(x);
}
var r4 = foo2(1, i2); // string, instantiated generic
var r4 = foo2(1, i2); // error
var r4b = foo2(1, a); // any
var r5 = foo2(1, i); // any
var r6 = foo2('', i2); // string
@ -66,5 +66,5 @@ function foo3(x, cb, y) {
}
var r7 = foo3(null, i, ''); // any
var r7b = foo3(null, a, ''); // any
var r8 = foo3(1, i2, 1); // {}
var r8 = foo3(1, i2, 1); // error
var r9 = foo3('', i2, ''); // string

View File

@ -1,161 +0,0 @@
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts ===
// Generic functions used as arguments for function typed parameters are not used to make inferences from
// Using construct signature arguments, no errors expected
function foo<T>(x: new(a: T) => T) {
>foo : <T>(x: new (a: T) => T) => T
>T : T
>x : new (a: T) => T
>a : T
>T : T
>T : T
return new x(null);
>new x(null) : T
>x : new (a: T) => T
}
interface I {
>I : I
new <T>(x: T): T;
>T : T
>x : T
>T : T
>T : T
}
interface I2<T> {
>I2 : I2<T>
>T : T
new (x: T): T;
>x : T
>T : T
>T : T
}
var i: I;
>i : I
>I : I
var i2: I2<string>;
>i2 : I2<string>
>I2 : I2<T>
var a: {
>a : new <T>(x: T) => T
new <T>(x: T): T;
>T : T
>x : T
>T : T
>T : T
}
var r = foo(i); // any
>r : any
>foo(i) : any
>foo : <T>(x: new (a: T) => T) => T
>i : I
var r2 = foo<string>(i); // string
>r2 : string
>foo<string>(i) : string
>foo : <T>(x: new (a: T) => T) => T
>i : I
var r3 = foo(i2); // string
>r3 : string
>foo(i2) : string
>foo : <T>(x: new (a: T) => T) => T
>i2 : I2<string>
var r3b = foo(a); // any
>r3b : any
>foo(a) : any
>foo : <T>(x: new (a: T) => T) => T
>a : new <T>(x: T) => T
function foo2<T, U>(x: T, cb: new(a: T) => U) {
>foo2 : <T, U>(x: T, cb: new (a: T) => U) => U
>T : T
>U : U
>x : T
>T : T
>cb : new (a: T) => U
>a : T
>T : T
>U : U
return new cb(x);
>new cb(x) : U
>cb : new (a: T) => U
>x : T
}
var r4 = foo2(1, i2); // string, instantiated generic
>r4 : string
>foo2(1, i2) : string
>foo2 : <T, U>(x: T, cb: new (a: T) => U) => U
>i2 : I2<string>
var r4b = foo2(1, a); // any
>r4b : any
>foo2(1, a) : any
>foo2 : <T, U>(x: T, cb: new (a: T) => U) => U
>a : new <T>(x: T) => T
var r5 = foo2(1, i); // any
>r5 : any
>foo2(1, i) : any
>foo2 : <T, U>(x: T, cb: new (a: T) => U) => U
>i : I
var r6 = foo2<string, string>('', i2); // string
>r6 : string
>foo2<string, string>('', i2) : string
>foo2 : <T, U>(x: T, cb: new (a: T) => U) => U
>i2 : I2<string>
function foo3<T, U>(x: T, cb: new(a: T) => U, y: U) {
>foo3 : <T, U>(x: T, cb: new (a: T) => U, y: U) => U
>T : T
>U : U
>x : T
>T : T
>cb : new (a: T) => U
>a : T
>T : T
>U : U
>y : U
>U : U
return new cb(x);
>new cb(x) : U
>cb : new (a: T) => U
>x : T
}
var r7 = foo3(null, i, ''); // any
>r7 : any
>foo3(null, i, '') : any
>foo3 : <T, U>(x: T, cb: new (a: T) => U, y: U) => U
>i : I
var r7b = foo3(null, a, ''); // any
>r7b : any
>foo3(null, a, '') : any
>foo3 : <T, U>(x: T, cb: new (a: T) => U, y: U) => U
>a : new <T>(x: T) => T
var r8 = foo3(1, i2, 1); // {}
>r8 : {}
>foo3(1, i2, 1) : {}
>foo3 : <T, U>(x: T, cb: new (a: T) => U, y: U) => U
>i2 : I2<string>
var r9 = foo3<string, string>('', i2, ''); // string
>r9 : string
>foo3<string, string>('', i2, '') : string
>foo3 : <T, U>(x: T, cb: new (a: T) => U, y: U) => U
>i2 : I2<string>

View File

@ -1,51 +1,106 @@
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(14,17): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(15,18): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(24,19): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(36,32): error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(10,29): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(15,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(16,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(25,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(37,36): error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(50,21): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(51,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(60,23): error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(67,51): error TS2304: Cannot find name 'U'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(67,57): error TS2304: Cannot find name 'U'.
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts (4 errors) ====
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts (10 errors) ====
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
function foo<T>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
module onlyT {
function foo<T>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => '');
var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => '');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
function other2<T extends Date>(x: T) {
var r7 = foo((a: T) => a, (b: T) => b); // T => T
// BUG 835518
var r9 = r7(new Date()); // should be ok
~~~~~~~~~~
function other2<T extends Date>(x: T) {
var r7 = foo((a: T) => a, (b: T) => b); // T => T
// BUG 835518
var r9 = r7(new Date()); // should be ok
~~~~~~~~~~
!!! error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
var r10 = r7(1); // error
~
var r10 = r7(1); // error
~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'.
}
}
function foo2<T extends Date>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
function foo2<T extends Date>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
function other3<T extends RegExp>(x: T) {
var r7 = foo2((a: T) => a, (b: T) => b); // error
~~~~~~~~~~~
function other3<T extends RegExp>(x: T) {
var r7 = foo2((a: T) => a, (b: T) => b); // error
~~~~~~~~~~~
!!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date
var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date
}
enum E { A }
enum F { A }
function foo3<T>(x: T, a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error
~~~~~~~~~~
!!! error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'.
}
enum E { A }
enum F { A }
module TU {
function foo<T, U>(a: (x: T) => T, b: (x: U) => U) {
var r: (x: T) => T;
return r;
}
function foo3<T>(x: T, a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => '');
var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error
~~~~~~~~~~
!!! error TS2345: Argument of type '(x: E) => F' is not assignable to parameter of type '(x: E) => E'.
function other2<T extends Date>(x: T) {
var r7 = foo((a: T) => a, (b: T) => b);
var r9 = r7(new Date());
~~~~~~~~~~
!!! error TS2345: Argument of type 'Date' is not assignable to parameter of type 'T'.
var r10 = r7(1);
~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'T'.
}
function foo2<T extends Date, U extends Date>(a: (x: T) => T, b: (x: U) => U) {
var r: (x: T) => T;
return r;
}
function other3<T extends RegExp>(x: T) {
var r7 = foo2((a: T) => a, (b: T) => b);
~~~~~~~~~~~
!!! error TS2345: Argument of type '(a: T) => T' is not assignable to parameter of type '(x: Date) => Date'.
var r7b = foo2((a) => a, (b) => b);
}
enum E { A }
enum F { A }
function foo3<T>(x: T, a: (x: T) => T, b: (x: U) => U) {
~
!!! error TS2304: Cannot find name 'U'.
~
!!! error TS2304: Cannot find name 'U'.
var r: (x: T) => T;
return r;
}
var r7 = foo3(E.A, (x) => E.A, (x) => F.A);
}

View File

@ -2,72 +2,146 @@
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
function foo<T>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
module onlyT {
function foo<T>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => '');
function other2<T extends Date>(x: T) {
var r7 = foo((a: T) => a, (b: T) => b); // T => T
// BUG 835518
var r9 = r7(new Date()); // should be ok
var r10 = r7(1); // error
}
function foo2<T extends Date>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
function other3<T extends RegExp>(x: T) {
var r7 = foo2((a: T) => a, (b: T) => b); // error
var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date
}
enum E { A }
enum F { A }
function foo3<T>(x: T, a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error
}
var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => '');
module TU {
function foo<T, U>(a: (x: T) => T, b: (x: U) => U) {
var r: (x: T) => T;
return r;
}
function other2<T extends Date>(x: T) {
var r7 = foo((a: T) => a, (b: T) => b); // T => T
// BUG 835518
var r9 = r7(new Date()); // should be ok
var r10 = r7(1); // error
}
var r1: (x: {}) => {} = foo((x: number) => 1, (x: string) => '');
function foo2<T extends Date>(a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
function other2<T extends Date>(x: T) {
var r7 = foo((a: T) => a, (b: T) => b);
var r9 = r7(new Date());
var r10 = r7(1);
}
function other3<T extends RegExp>(x: T) {
var r7 = foo2((a: T) => a, (b: T) => b); // error
var r7b = foo2((a) => a, (b) => b); // valid, T is inferred to be Date
}
function foo2<T extends Date, U extends Date>(a: (x: T) => T, b: (x: U) => U) {
var r: (x: T) => T;
return r;
}
enum E { A }
enum F { A }
function other3<T extends RegExp>(x: T) {
var r7 = foo2((a: T) => a, (b: T) => b);
var r7b = foo2((a) => a, (b) => b);
}
function foo3<T>(x: T, a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
enum E { A }
enum F { A }
var r7 = foo3(E.A, (x) => E.A, (x) => F.A); // error
function foo3<T>(x: T, a: (x: T) => T, b: (x: U) => U) {
var r: (x: T) => T;
return r;
}
var r7 = foo3(E.A, (x) => E.A, (x) => F.A);
}
//// [genericCallWithGenericSignatureArguments2.js]
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
function foo(a, b) {
var r;
return r;
}
var r1 = foo(function (x) { return 1; }, function (x) { return ''; });
function other2(x) {
var r7 = foo(function (a) { return a; }, function (b) { return b; }); // T => T
// BUG 835518
var r9 = r7(new Date()); // should be ok
var r10 = r7(1); // error
}
function foo2(a, b) {
var r;
return r;
}
function other3(x) {
var r7 = foo2(function (a) { return a; }, function (b) { return b; }); // error
var r7b = foo2(function (a) { return a; }, function (b) { return b; }); // valid, T is inferred to be Date
}
var E;
(function (E) {
E[E["A"] = 0] = "A";
})(E || (E = {}));
var F;
(function (F) {
F[F["A"] = 0] = "A";
})(F || (F = {}));
function foo3(x, a, b) {
var r;
return r;
}
var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); // error
var onlyT;
(function (onlyT) {
function foo(a, b) {
var r;
return r;
}
var r1 = foo(function (x) { return 1; }, function (x) { return ''; });
function other2(x) {
var r7 = foo(function (a) { return a; }, function (b) { return b; }); // T => T
// BUG 835518
var r9 = r7(new Date()); // should be ok
var r10 = r7(1); // error
}
function foo2(a, b) {
var r;
return r;
}
function other3(x) {
var r7 = foo2(function (a) { return a; }, function (b) { return b; }); // error
var r7b = foo2(function (a) { return a; }, function (b) { return b; }); // valid, T is inferred to be Date
}
var E;
(function (E) {
E[E["A"] = 0] = "A";
})(E || (E = {}));
var F;
(function (F) {
F[F["A"] = 0] = "A";
})(F || (F = {}));
function foo3(x, a, b) {
var r;
return r;
}
var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); // error
})(onlyT || (onlyT = {}));
var TU;
(function (TU) {
function foo(a, b) {
var r;
return r;
}
var r1 = foo(function (x) { return 1; }, function (x) { return ''; });
function other2(x) {
var r7 = foo(function (a) { return a; }, function (b) { return b; });
var r9 = r7(new Date());
var r10 = r7(1);
}
function foo2(a, b) {
var r;
return r;
}
function other3(x) {
var r7 = foo2(function (a) { return a; }, function (b) { return b; });
var r7b = foo2(function (a) { return a; }, function (b) { return b; });
}
var E;
(function (E) {
E[E["A"] = 0] = "A";
})(E || (E = {}));
var F;
(function (F) {
F[F["A"] = 0] = "A";
})(F || (F = {}));
function foo3(x, a, b) {
var r;
return r;
}
var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; });
})(TU || (TU = {}));

View File

@ -0,0 +1,42 @@
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(32,11): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(33,11): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts (2 errors) ====
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
function foo<T>(x: T, a: (x: T) => T, b: (x: T) => T) {
var r: (x: T) => T;
return r;
}
var r1 = foo('', (x: string) => '', (x: Object) => null); // any => any
var r1ii = foo('', (x) => '', (x) => null); // string => string
var r2 = foo('', (x: string) => '', (x: Object) => ''); // string => string
var r3 = foo(null, (x: Object) => '', (x: string) => ''); // Object => Object
var r4 = foo(null, (x) => '', (x) => ''); // any => any
var r5 = foo(new Object(), (x) => '', (x) => ''); // Object => Object
enum E { A }
enum F { A }
var r6 = foo(E.A, (x: number) => E.A, (x: F) => F.A); // number => number
function foo2<T, U>(x: T, a: (x: T) => U, b: (x: T) => U) {
var r: (x: T) => U;
return r;
}
var r8 = foo2('', (x) => '', (x) => null); // string => string
var r9 = foo2(null, (x) => '', (x) => ''); // any => any
var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object
var x: (a: string) => boolean;
var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.

View File

@ -30,8 +30,8 @@ var r9 = foo2(null, (x) => '', (x) => ''); // any => any
var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object
var x: (a: string) => boolean;
var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // {} => {}
var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // (string => boolean) => {}
var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error
var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error
//// [genericCallWithGenericSignatureArguments3.js]
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
@ -63,5 +63,5 @@ var r8 = foo2('', function (x) { return ''; }, function (x) { return null; }); /
var r9 = foo2(null, function (x) { return ''; }, function (x) { return ''; }); // any => any
var r10 = foo2(null, function (x) { return ''; }, function (x) { return ''; }); // Object => Object
var x;
var r11 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // {} => {}
var r12 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // (string => boolean) => {}
var r11 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // error
var r12 = foo2(x, function (a1) { return function (n) { return 1; }; }, function (a2) { return 2; }); // error

View File

@ -1,202 +0,0 @@
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts ===
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made,
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them.
function foo<T>(x: T, a: (x: T) => T, b: (x: T) => T) {
>foo : <T>(x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T
>T : T
>x : T
>T : T
>a : (x: T) => T
>x : T
>T : T
>T : T
>b : (x: T) => T
>x : T
>T : T
>T : T
var r: (x: T) => T;
>r : (x: T) => T
>x : T
>T : T
>T : T
return r;
>r : (x: T) => T
}
var r1 = foo('', (x: string) => '', (x: Object) => null); // any => any
>r1 : (x: any) => any
>foo('', (x: string) => '', (x: Object) => null) : (x: any) => any
>foo : <T>(x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T
>(x: string) => '' : (x: string) => string
>x : string
>(x: Object) => null : (x: Object) => any
>x : Object
>Object : Object
var r1ii = foo('', (x) => '', (x) => null); // string => string
>r1ii : (x: string) => string
>foo('', (x) => '', (x) => null) : (x: string) => string
>foo : <T>(x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T
>(x) => '' : (x: string) => string
>x : string
>(x) => null : (x: string) => any
>x : string
var r2 = foo('', (x: string) => '', (x: Object) => ''); // string => string
>r2 : (x: Object) => Object
>foo('', (x: string) => '', (x: Object) => '') : (x: Object) => Object
>foo : <T>(x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T
>(x: string) => '' : (x: string) => string
>x : string
>(x: Object) => '' : (x: Object) => string
>x : Object
>Object : Object
var r3 = foo(null, (x: Object) => '', (x: string) => ''); // Object => Object
>r3 : (x: Object) => Object
>foo(null, (x: Object) => '', (x: string) => '') : (x: Object) => Object
>foo : <T>(x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T
>(x: Object) => '' : (x: Object) => string
>x : Object
>Object : Object
>(x: string) => '' : (x: string) => string
>x : string
var r4 = foo(null, (x) => '', (x) => ''); // any => any
>r4 : (x: any) => any
>foo(null, (x) => '', (x) => '') : (x: any) => any
>foo : <T>(x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T
>(x) => '' : (x: any) => string
>x : any
>(x) => '' : (x: any) => string
>x : any
var r5 = foo(new Object(), (x) => '', (x) => ''); // Object => Object
>r5 : (x: Object) => Object
>foo(new Object(), (x) => '', (x) => '') : (x: Object) => Object
>foo : <T>(x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T
>new Object() : Object
>Object : { (): any; (value: any): any; new (value?: any): Object; prototype: Object; getPrototypeOf(o: any): any; getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor; getOwnPropertyNames(o: any): string[]; create(o: any, properties?: PropertyDescriptorMap): any; defineProperty(o: any, p: string, attributes: PropertyDescriptor): any; defineProperties(o: any, properties: PropertyDescriptorMap): any; seal(o: any): any; freeze(o: any): any; preventExtensions(o: any): any; isSealed(o: any): boolean; isFrozen(o: any): boolean; isExtensible(o: any): boolean; keys(o: any): string[]; }
>(x) => '' : (x: Object) => string
>x : Object
>(x) => '' : (x: Object) => string
>x : Object
enum E { A }
>E : E
>A : E
enum F { A }
>F : F
>A : F
var r6 = foo(E.A, (x: number) => E.A, (x: F) => F.A); // number => number
>r6 : (x: number) => number
>foo(E.A, (x: number) => E.A, (x: F) => F.A) : (x: number) => number
>foo : <T>(x: T, a: (x: T) => T, b: (x: T) => T) => (x: T) => T
>E.A : E
>E : typeof E
>A : E
>(x: number) => E.A : (x: number) => E
>x : number
>E.A : E
>E : typeof E
>A : E
>(x: F) => F.A : (x: F) => F
>x : F
>F : F
>F.A : F
>F : typeof F
>A : F
function foo2<T, U>(x: T, a: (x: T) => U, b: (x: T) => U) {
>foo2 : <T, U>(x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U
>T : T
>U : U
>x : T
>T : T
>a : (x: T) => U
>x : T
>T : T
>U : U
>b : (x: T) => U
>x : T
>T : T
>U : U
var r: (x: T) => U;
>r : (x: T) => U
>x : T
>T : T
>U : U
return r;
>r : (x: T) => U
}
var r8 = foo2('', (x) => '', (x) => null); // string => string
>r8 : (x: string) => any
>foo2('', (x) => '', (x) => null) : (x: string) => any
>foo2 : <T, U>(x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U
>(x) => '' : (x: string) => string
>x : string
>(x) => null : (x: string) => any
>x : string
var r9 = foo2(null, (x) => '', (x) => ''); // any => any
>r9 : (x: any) => string
>foo2(null, (x) => '', (x) => '') : (x: any) => string
>foo2 : <T, U>(x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U
>(x) => '' : (x: any) => string
>x : any
>(x) => '' : (x: any) => string
>x : any
var r10 = foo2(null, (x: Object) => '', (x: string) => ''); // Object => Object
>r10 : (x: Object) => string
>foo2(null, (x: Object) => '', (x: string) => '') : (x: Object) => string
>foo2 : <T, U>(x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U
>(x: Object) => '' : (x: Object) => string
>x : Object
>Object : Object
>(x: string) => '' : (x: string) => string
>x : string
var x: (a: string) => boolean;
>x : (a: string) => boolean
>a : string
var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // {} => {}
>r11 : (x: {}) => {}
>foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2) : (x: {}) => {}
>foo2 : <T, U>(x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U
>x : (a: string) => boolean
>(a1: (y: string) => string) => (n: Object) => 1 : (a1: (y: string) => string) => (n: Object) => number
>a1 : (y: string) => string
>y : string
>(n: Object) => 1 : (n: Object) => number
>n : Object
>Object : Object
>(a2: (z: string) => string) => 2 : (a2: (z: string) => string) => number
>a2 : (z: string) => string
>z : string
var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // (string => boolean) => {}
>r12 : (x: (a: string) => boolean) => {}
>foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2) : (x: (a: string) => boolean) => {}
>foo2 : <T, U>(x: T, a: (x: T) => U, b: (x: T) => U) => (x: T) => U
>x : (a: string) => boolean
>(a1: (y: string) => boolean) => (n: Object) => 1 : (a1: (y: string) => boolean) => (n: Object) => number
>a1 : (y: string) => boolean
>y : string
>(n: Object) => 1 : (n: Object) => number
>n : Object
>Object : Object
>(a2: (z: string) => boolean) => 2 : (a2: (z: string) => boolean) => number
>a2 : (z: string) => boolean
>z : string

View File

@ -0,0 +1,14 @@
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts(5,9): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts (1 errors) ====
function foo<T>(x: { bar: T; baz: T }) {
return x;
}
var r = foo({ bar: 1, baz: '' }); // error
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var r2 = foo({ bar: 1, baz: 1 }); // T = number
var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo
var r4 = foo<Object>({ bar: 1, baz: '' }); // T = Object

View File

@ -3,7 +3,7 @@ function foo<T>(x: { bar: T; baz: T }) {
return x;
}
var r = foo({ bar: 1, baz: '' }); // T = {}
var r = foo({ bar: 1, baz: '' }); // error
var r2 = foo({ bar: 1, baz: 1 }); // T = number
var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo
var r4 = foo<Object>({ bar: 1, baz: '' }); // T = Object
@ -12,7 +12,7 @@ var r4 = foo<Object>({ bar: 1, baz: '' }); // T = Object
function foo(x) {
return x;
}
var r = foo({ bar: 1, baz: '' }); // T = {}
var r = foo({ bar: 1, baz: '' }); // error
var r2 = foo({ bar: 1, baz: 1 }); // T = number
var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo
var r4 = foo({ bar: 1, baz: '' }); // T = Object

View File

@ -1,49 +0,0 @@
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts ===
function foo<T>(x: { bar: T; baz: T }) {
>foo : <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }
>T : T
>x : { bar: T; baz: T; }
>bar : T
>T : T
>baz : T
>T : T
return x;
>x : { bar: T; baz: T; }
}
var r = foo({ bar: 1, baz: '' }); // T = {}
>r : { bar: {}; baz: {}; }
>foo({ bar: 1, baz: '' }) : { bar: {}; baz: {}; }
>foo : <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }
>{ bar: 1, baz: '' } : { bar: number; baz: string; }
>bar : number
>baz : string
var r2 = foo({ bar: 1, baz: 1 }); // T = number
>r2 : { bar: number; baz: number; }
>foo({ bar: 1, baz: 1 }) : { bar: number; baz: number; }
>foo : <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }
>{ bar: 1, baz: 1 } : { bar: number; baz: number; }
>bar : number
>baz : number
var r3 = foo({ bar: foo, baz: foo }); // T = typeof foo
>r3 : { bar: <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }; }
>foo({ bar: foo, baz: foo }) : { bar: <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }; }
>foo : <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }
>{ bar: foo, baz: foo } : { bar: <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }; baz: <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }; }
>bar : <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }
>foo : <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }
>baz : <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }
>foo : <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }
var r4 = foo<Object>({ bar: 1, baz: '' }); // T = Object
>r4 : { bar: Object; baz: Object; }
>foo<Object>({ bar: 1, baz: '' }) : { bar: Object; baz: Object; }
>foo : <T>(x: { bar: T; baz: T; }) => { bar: T; baz: T; }
>Object : Object
>{ bar: 1, baz: '' } : { bar: number; baz: string; }
>bar : number
>baz : string

View File

@ -1,3 +1,4 @@
tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(2,9): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(4,22): error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type '{ x: number; y: number; }'.
Types of property 'y' are incompatible:
Type 'string' is not assignable to type 'number'.
@ -12,9 +13,11 @@ tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts(7,22): error TS23
Type 'number' is not assignable to type 'string'.
==== tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts (4 errors) ====
==== tests/cases/compiler/genericCallWithObjectLiteralArguments1.ts (5 errors) ====
function foo<T>(n: { x: T; y: T }, m: T) { return m; }
var x = foo({ x: 3, y: "" }, 4); // no error, x is Object, the best common type
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
// these are all errors
var x2 = foo<number>({ x: 3, y: "" }, 4);
~~~~~~~~~~~~~~~

View File

@ -0,0 +1,27 @@
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts(20,9): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts (1 errors) ====
class C {
private x: string;
}
class D {
private x: string;
}
class X<T> {
x: T;
}
function foo<T>(t: X<T>, t2: X<T>) {
var x: T;
return x;
}
var c1 = new X<C>();
var d1 = new X<D>();
var r = foo(c1, d1); // error
~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var r2 = foo(c1, c1); // ok

View File

@ -1,68 +0,0 @@
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgs.ts ===
class C {
>C : C
private x: string;
>x : string
}
class D {
>D : D
private x: string;
>x : string
}
class X<T> {
>X : X<T>
>T : T
x: T;
>x : T
>T : T
}
function foo<T>(t: X<T>, t2: X<T>) {
>foo : <T>(t: X<T>, t2: X<T>) => T
>T : T
>t : X<T>
>X : X<T>
>T : T
>t2 : X<T>
>X : X<T>
>T : T
var x: T;
>x : T
>T : T
return x;
>x : T
}
var c1 = new X<C>();
>c1 : X<C>
>new X<C>() : X<C>
>X : typeof X
>C : C
var d1 = new X<D>();
>d1 : X<D>
>new X<D>() : X<D>
>X : typeof X
>D : D
var r = foo(c1, d1); // error
>r : {}
>foo(c1, d1) : {}
>foo : <T>(t: X<T>, t2: X<T>) => T
>c1 : X<C>
>d1 : X<D>
var r2 = foo(c1, c1); // ok
>r2 : C
>foo(c1, c1) : C
>foo : <T>(t: X<T>, t2: X<T>) => T
>c1 : X<C>
>c1 : X<C>

View File

@ -22,7 +22,7 @@ class Derived2 extends Base {
// returns {}[]
function f<T extends Base, U extends Base>(a: { x: T; y: U }) {
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => {}[]
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => Array<T | U>
>T : T
>Base : Base
>U : U
@ -34,7 +34,7 @@ function f<T extends Base, U extends Base>(a: { x: T; y: U }) {
>U : U
return [a.x, a.y];
>[a.x, a.y] : {}[]
>[a.x, a.y] : Array<T | U>
>a.x : T
>a : { x: T; y: U; }
>x : T
@ -44,9 +44,9 @@ function f<T extends Base, U extends Base>(a: { x: T; y: U }) {
}
var r = f({ x: new Derived(), y: new Derived2() }); // {}[]
>r : {}[]
>f({ x: new Derived(), y: new Derived2() }) : {}[]
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => {}[]
>r : Array<Derived | Derived2>
>f({ x: new Derived(), y: new Derived2() }) : Array<Derived | Derived2>
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => Array<T | U>
>{ x: new Derived(), y: new Derived2() } : { x: Derived; y: Derived2; }
>x : Derived
>new Derived() : Derived
@ -56,9 +56,9 @@ var r = f({ x: new Derived(), y: new Derived2() }); // {}[]
>Derived2 : typeof Derived2
var r2 = f({ x: new Base(), y: new Derived2() }); // {}[]
>r2 : {}[]
>f({ x: new Base(), y: new Derived2() }) : {}[]
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => {}[]
>r2 : Base[]
>f({ x: new Base(), y: new Derived2() }) : Array<Base | Derived2>
>f : <T extends Base, U extends Base>(a: { x: T; y: U; }) => Array<T | U>
>{ x: new Base(), y: new Derived2() } : { x: Base; y: Derived2; }
>x : Base
>new Base() : Base

View File

@ -1,7 +1,8 @@
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(18,10): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts(20,29): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list.
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts (1 errors) ====
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndConstraints3.ts (2 errors) ====
// Generic call with constraints infering type parameter from object member properties
class Base {
@ -20,6 +21,8 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObj
}
var r1 = f({ x: new Derived(), y: new Derived2() }); // ok, both extend Base
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
function f2<T extends Base, U extends { x: T; y: T }>(a: U) {
~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -0,0 +1,54 @@
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts(36,14): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts (1 errors) ====
// Function typed arguments with multiple signatures must be passed an implementation that matches all of them
// Inferences are made quadratic-pairwise to and from these overload sets
module NonGenericParameter {
var a: {
new(x: boolean): boolean;
new(x: string): string;
}
function foo4(cb: typeof a) {
return new cb(null);
}
var r = foo4(a);
var b: { new <T>(x: T): T };
var r2 = foo4(b);
}
module GenericParameter {
function foo5<T>(cb: { new(x: T): string; new(x: number): T }) {
return cb;
}
var a: {
new (x: boolean): string;
new (x: number): boolean;
}
var r5 = foo5(a); // new{} => string; new(x:number) => {}
var b: { new<T>(x: T): string; new<T>(x: number): T; }
var r7 = foo5(b); // new any => string; new(x:number) => any
function foo6<T>(cb: { new(x: T): string; new(x: T, y?: T): string }) {
return cb;
}
var r8 = foo6(a); // error
~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string
function foo7<T>(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) {
return cb;
}
var r13 = foo7(1, b); // new any => string; new(x:any, y?:any) => string
var c: { new <T>(x: T): string; <T>(x: number): T; }
var c2: { new <T>(x: T): string; new<T>(x: number): T; }
var r14 = foo7(1, c); // new any => string; new(x:any, y?:any) => string
var r15 = foo7(1, c2); // new any => string; new(x:any, y?:any) => string
}

View File

@ -34,7 +34,7 @@ module GenericParameter {
return cb;
}
var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string
var r8 = foo6(a); // error
var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string
function foo7<T>(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) {
@ -73,7 +73,7 @@ var GenericParameter;
function foo6(cb) {
return cb;
}
var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string
var r8 = foo6(a); // error
var r9 = foo6(b); // new any => string; new(x:any, y?:any) => string
function foo7(x, cb) {
return cb;

Some files were not shown because too many files have changed in this diff Show More