Merge branch 'release-1.4' into parsePrimaryExpression

This commit is contained in:
Jason Freeman
2014-12-16 11:25:57 -08:00
30 changed files with 34651 additions and 6048 deletions
+64 -23
View File
@@ -124,10 +124,7 @@ interface Object {
propertyIsEnumerable(v: string): boolean;
}
/**
* Provides functionality common to all JavaScript objects.
*/
declare var Object: {
interface ObjectConstructor {
new (value?: any): Object;
(): any;
(value: any): any;
@@ -221,6 +218,11 @@ declare var Object: {
keys(o: any): string[];
}
/**
* Provides functionality common to all JavaScript objects.
*/
declare var Object: ObjectConstructor;
/**
* Creates a new function.
*/
@@ -255,8 +257,8 @@ interface Function {
caller: Function;
}
declare var Function: {
/**
interface FunctionConstructor {
/**
* Creates a new function.
* @param args A list of arguments the function accepts.
*/
@@ -265,6 +267,8 @@ declare var Function: {
prototype: Function;
}
declare var Function: FunctionConstructor;
interface IArguments {
[index: number]: any;
length: number;
@@ -424,24 +428,29 @@ interface String {
[index: number]: string;
}
/**
* Allows manipulation and formatting of text strings and determination and location of substrings within strings.
*/
declare var String: {
interface StringConstructor {
new (value?: any): String;
(value?: any): string;
prototype: String;
fromCharCode(...codes: number[]): string;
}
/**
* Allows manipulation and formatting of text strings and determination and location of substrings within strings.
*/
declare var String: StringConstructor;
interface Boolean {
}
declare var Boolean: {
interface BooleanConstructor {
new (value?: any): Boolean;
(value?: any): boolean;
prototype: Boolean;
}
declare var Boolean: BooleanConstructor;
interface Number {
/**
* Returns a string representation of an object.
@@ -468,8 +477,7 @@ interface Number {
toPrecision(precision?: number): string;
}
/** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */
declare var Number: {
interface NumberConstructor {
new (value?: any): Number;
(value?: any): number;
prototype: Number;
@@ -499,6 +507,9 @@ declare var Number: {
POSITIVE_INFINITY: number;
}
/** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */
declare var Number: NumberConstructor;
interface TemplateStringsArray extends Array<string> {
raw: string[];
}
@@ -768,7 +779,7 @@ interface Date {
toJSON(key?: any): string;
}
declare var Date: {
interface DateConstructor {
new (): Date;
new (value: number): Date;
new (value: string): Date;
@@ -794,6 +805,8 @@ declare var Date: {
now(): number;
}
declare var Date: DateConstructor;
interface RegExpMatchArray extends Array<string> {
index?: number;
input?: string;
@@ -834,9 +847,11 @@ interface RegExp {
// Non-standard extensions
compile(): RegExp;
}
declare var RegExp: {
interface RegExpConstructor {
new (pattern: string, flags?: string): RegExp;
(pattern: string, flags?: string): RegExp;
prototype: RegExp;
// Non-standard extensions
$1: string;
@@ -851,64 +866,87 @@ declare var RegExp: {
lastMatch: string;
}
declare var RegExp: RegExpConstructor;
interface Error {
name: string;
message: string;
}
declare var Error: {
interface ErrorConstructor {
new (message?: string): Error;
(message?: string): Error;
prototype: Error;
}
declare var Error: ErrorConstructor;
interface EvalError extends Error {
}
declare var EvalError: {
interface EvalErrorConstructor {
new (message?: string): EvalError;
(message?: string): EvalError;
prototype: EvalError;
}
declare var EvalError: EvalErrorConstructor;
interface RangeError extends Error {
}
declare var RangeError: {
interface RangeErrorConstructor {
new (message?: string): RangeError;
(message?: string): RangeError;
prototype: RangeError;
}
declare var RangeError: RangeErrorConstructor;
interface ReferenceError extends Error {
}
declare var ReferenceError: {
interface ReferenceErrorConstructor {
new (message?: string): ReferenceError;
(message?: string): ReferenceError;
prototype: ReferenceError;
}
declare var ReferenceError: ReferenceErrorConstructor;
interface SyntaxError extends Error {
}
declare var SyntaxError: {
interface SyntaxErrorConstructor {
new (message?: string): SyntaxError;
(message?: string): SyntaxError;
prototype: SyntaxError;
}
declare var SyntaxError: SyntaxErrorConstructor;
interface TypeError extends Error {
}
declare var TypeError: {
interface TypeErrorConstructor {
new (message?: string): TypeError;
(message?: string): TypeError;
prototype: TypeError;
}
declare var TypeError: TypeErrorConstructor;
interface URIError extends Error {
}
declare var URIError: {
interface URIErrorConstructor {
new (message?: string): URIError;
(message?: string): URIError;
prototype: URIError;
}
declare var URIError: URIErrorConstructor;
interface JSON {
/**
* Converts a JavaScript Object Notation (JSON) string into an object.
@@ -1111,7 +1149,8 @@ interface Array<T> {
[n: number]: T;
}
declare var Array: {
interface ArrayConstructor {
new (arrayLength?: number): any[];
new <T>(arrayLength: number): T[];
new <T>(...items: T[]): T[];
@@ -1121,3 +1160,5 @@ declare var Array: {
isArray(arg: any): boolean;
prototype: Array<any>;
}
declare var Array: ArrayConstructor;
+4801
View File
File diff suppressed because it is too large Load Diff
+71 -25
View File
@@ -124,10 +124,7 @@ interface Object {
propertyIsEnumerable(v: string): boolean;
}
/**
* Provides functionality common to all JavaScript objects.
*/
declare var Object: {
interface ObjectConstructor {
new (value?: any): Object;
(): any;
(value: any): any;
@@ -221,6 +218,11 @@ declare var Object: {
keys(o: any): string[];
}
/**
* Provides functionality common to all JavaScript objects.
*/
declare var Object: ObjectConstructor;
/**
* Creates a new function.
*/
@@ -255,8 +257,8 @@ interface Function {
caller: Function;
}
declare var Function: {
/**
interface FunctionConstructor {
/**
* Creates a new function.
* @param args A list of arguments the function accepts.
*/
@@ -265,6 +267,8 @@ declare var Function: {
prototype: Function;
}
declare var Function: FunctionConstructor;
interface IArguments {
[index: number]: any;
length: number;
@@ -424,24 +428,29 @@ interface String {
[index: number]: string;
}
/**
* Allows manipulation and formatting of text strings and determination and location of substrings within strings.
*/
declare var String: {
interface StringConstructor {
new (value?: any): String;
(value?: any): string;
prototype: String;
fromCharCode(...codes: number[]): string;
}
/**
* Allows manipulation and formatting of text strings and determination and location of substrings within strings.
*/
declare var String: StringConstructor;
interface Boolean {
}
declare var Boolean: {
interface BooleanConstructor {
new (value?: any): Boolean;
(value?: any): boolean;
prototype: Boolean;
}
declare var Boolean: BooleanConstructor;
interface Number {
/**
* Returns a string representation of an object.
@@ -468,8 +477,7 @@ interface Number {
toPrecision(precision?: number): string;
}
/** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */
declare var Number: {
interface NumberConstructor {
new (value?: any): Number;
(value?: any): number;
prototype: Number;
@@ -499,6 +507,9 @@ declare var Number: {
POSITIVE_INFINITY: number;
}
/** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */
declare var Number: NumberConstructor;
interface TemplateStringsArray extends Array<string> {
raw: string[];
}
@@ -768,7 +779,7 @@ interface Date {
toJSON(key?: any): string;
}
declare var Date: {
interface DateConstructor {
new (): Date;
new (value: number): Date;
new (value: string): Date;
@@ -794,6 +805,8 @@ declare var Date: {
now(): number;
}
declare var Date: DateConstructor;
interface RegExpMatchArray extends Array<string> {
index?: number;
input?: string;
@@ -834,9 +847,11 @@ interface RegExp {
// Non-standard extensions
compile(): RegExp;
}
declare var RegExp: {
interface RegExpConstructor {
new (pattern: string, flags?: string): RegExp;
(pattern: string, flags?: string): RegExp;
prototype: RegExp;
// Non-standard extensions
$1: string;
@@ -851,64 +866,87 @@ declare var RegExp: {
lastMatch: string;
}
declare var RegExp: RegExpConstructor;
interface Error {
name: string;
message: string;
}
declare var Error: {
interface ErrorConstructor {
new (message?: string): Error;
(message?: string): Error;
prototype: Error;
}
declare var Error: ErrorConstructor;
interface EvalError extends Error {
}
declare var EvalError: {
interface EvalErrorConstructor {
new (message?: string): EvalError;
(message?: string): EvalError;
prototype: EvalError;
}
declare var EvalError: EvalErrorConstructor;
interface RangeError extends Error {
}
declare var RangeError: {
interface RangeErrorConstructor {
new (message?: string): RangeError;
(message?: string): RangeError;
prototype: RangeError;
}
declare var RangeError: RangeErrorConstructor;
interface ReferenceError extends Error {
}
declare var ReferenceError: {
interface ReferenceErrorConstructor {
new (message?: string): ReferenceError;
(message?: string): ReferenceError;
prototype: ReferenceError;
}
declare var ReferenceError: ReferenceErrorConstructor;
interface SyntaxError extends Error {
}
declare var SyntaxError: {
interface SyntaxErrorConstructor {
new (message?: string): SyntaxError;
(message?: string): SyntaxError;
prototype: SyntaxError;
}
declare var SyntaxError: SyntaxErrorConstructor;
interface TypeError extends Error {
}
declare var TypeError: {
interface TypeErrorConstructor {
new (message?: string): TypeError;
(message?: string): TypeError;
prototype: TypeError;
}
declare var TypeError: TypeErrorConstructor;
interface URIError extends Error {
}
declare var URIError: {
interface URIErrorConstructor {
new (message?: string): URIError;
(message?: string): URIError;
prototype: URIError;
}
declare var URIError: URIErrorConstructor;
interface JSON {
/**
* Converts a JavaScript Object Notation (JSON) string into an object.
@@ -1111,7 +1149,8 @@ interface Array<T> {
[n: number]: T;
}
declare var Array: {
interface ArrayConstructor {
new (arrayLength?: number): any[];
new <T>(arrayLength: number): T[];
new <T>(...items: T[]): T[];
@@ -1122,6 +1161,8 @@ declare var Array: {
prototype: Array<any>;
}
declare var Array: ArrayConstructor;
/////////////////////////////
/// IE10 ECMAScript Extensions
/////////////////////////////
@@ -1489,7 +1530,7 @@ interface Uint32Array extends ArrayBufferView {
set(array: number[], offset?: number): void;
/**
* Gets a new Uint32Array view of the ArrayBuffer Object store for this array, specifying the first and last members of the subarray.
* Gets a new Int8Array view of the ArrayBuffer Object store for this array, specifying the first and last members of the subarray.
* @param begin The index of the beginning of the array.
* @param end The index of the end of the array.
*/
@@ -1754,6 +1795,7 @@ interface Map<K, V> {
}
declare var Map: {
new <K, V>(): Map<K, V>;
prototype: Map<any, any>;
}
interface WeakMap<K, V> {
@@ -1765,6 +1807,7 @@ interface WeakMap<K, V> {
}
declare var WeakMap: {
new <K, V>(): WeakMap<K, V>;
prototype: WeakMap<any, any>;
}
interface Set<T> {
@@ -1777,10 +1820,13 @@ interface Set<T> {
}
declare var Set: {
new <T>(): Set<T>;
prototype: Set<any>;
}
/////////////////////////////
/// ECMAScript Internationalization API
/////////////////////////////
declare module Intl {
interface CollatorOptions {
usage?: string;
localeMatcher?: string;
+6 -1
View File
@@ -647,6 +647,7 @@ interface Map<K, V> {
}
declare var Map: {
new <K, V>(): Map<K, V>;
prototype: Map<any, any>;
}
interface WeakMap<K, V> {
@@ -658,6 +659,7 @@ interface WeakMap<K, V> {
}
declare var WeakMap: {
new <K, V>(): WeakMap<K, V>;
prototype: WeakMap<any, any>;
}
interface Set<T> {
@@ -670,10 +672,13 @@ interface Set<T> {
}
declare var Set: {
new <T>(): Set<T>;
prototype: Set<any>;
}
/////////////////////////////
/// ECMAScript Internationalization API
/////////////////////////////
declare module Intl {
interface CollatorOptions {
usage?: string;
localeMatcher?: string;
+17195
View File
File diff suppressed because it is too large Load Diff
+6 -1
View File
@@ -647,6 +647,7 @@ interface Map<K, V> {
}
declare var Map: {
new <K, V>(): Map<K, V>;
prototype: Map<any, any>;
}
interface WeakMap<K, V> {
@@ -658,6 +659,7 @@ interface WeakMap<K, V> {
}
declare var WeakMap: {
new <K, V>(): WeakMap<K, V>;
prototype: WeakMap<any, any>;
}
interface Set<T> {
@@ -670,10 +672,13 @@ interface Set<T> {
}
declare var Set: {
new <T>(): Set<T>;
prototype: Set<any>;
}
/////////////////////////////
/// ECMAScript Internationalization API
/////////////////////////////
declare module Intl {
interface CollatorOptions {
usage?: string;
localeMatcher?: string;
+3167 -2427
View File
File diff suppressed because it is too large Load Diff
+1849
View File
File diff suppressed because it is too large Load Diff
+1849
View File
File diff suppressed because it is too large Load Diff
+5157 -3564
View File
File diff suppressed because it is too large Load Diff
+20 -7
View File
@@ -4813,17 +4813,25 @@ module ts {
return undefined;
}
// In a typed function call, an argument expression is contextually typed by the type of the corresponding parameter.
function getContextualTypeForArgument(node: Expression): Type {
var callExpression = <CallExpression>node.parent;
var argIndex = indexOf(callExpression.arguments, node);
// In a typed function call, an argument or substitution expression is contextually typed by the type of the corresponding parameter.
function getContextualTypeForArgument(callTarget: CallLikeExpression, arg: Expression): Type {
var args = getEffectiveCallArguments(callTarget);
var argIndex = indexOf(args, arg);
if (argIndex >= 0) {
var signature = getResolvedSignature(callExpression);
var signature = getResolvedSignature(callTarget);
return getTypeAtPosition(signature, argIndex);
}
return undefined;
}
function getContextualTypeForSubstitutionExpression(template: TemplateExpression, substitutionExpression: Expression) {
if (template.parent.kind === SyntaxKind.TaggedTemplateExpression) {
return getContextualTypeForArgument(<TaggedTemplateExpression>template.parent, substitutionExpression);
}
return undefined;
}
function getContextualTypeForBinaryOperand(node: Expression): Type {
var binaryExpression = <BinaryExpression>node.parent;
var operator = binaryExpression.operator;
@@ -4959,7 +4967,7 @@ module ts {
return getContextualTypeForReturnExpression(node);
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
return getContextualTypeForArgument(node);
return getContextualTypeForArgument(<CallExpression>parent, node);
case SyntaxKind.TypeAssertionExpression:
return getTypeFromTypeNode((<TypeAssertion>parent).type);
case SyntaxKind.BinaryExpression:
@@ -4970,6 +4978,9 @@ module ts {
return getContextualTypeForElementExpression(node);
case SyntaxKind.ConditionalExpression:
return getContextualTypeForConditionalOperand(node);
case SyntaxKind.TemplateSpan:
Debug.assert(parent.parent.kind === SyntaxKind.TemplateExpression);
return getContextualTypeForSubstitutionExpression(<TemplateExpression>parent.parent, node);
}
return undefined;
}
@@ -5571,7 +5582,7 @@ module ts {
}
/**
* Returns the effective arguments for an expression that works like a function invokation.
* Returns the effective arguments for an expression that works like a function invocation.
*
* If 'node' is a CallExpression or a NewExpression, then its argument list is returned.
* If 'node' is a TaggedTemplateExpression, a new argument list is constructed from the substitution
@@ -8636,6 +8647,8 @@ module ts {
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
case SyntaxKind.TaggedTemplateExpression:
case SyntaxKind.TemplateExpression:
case SyntaxKind.TemplateSpan:
case SyntaxKind.TypeAssertionExpression:
case SyntaxKind.ParenthesizedExpression:
case SyntaxKind.TypeOfExpression:
@@ -0,0 +1,52 @@
//// [taggedTemplateContextualTyping1.ts]
type FuncType = (x: <T>(p: T) => T) => typeof x;
function tempTag1<T>(templateStrs: TemplateStringsArray, f: FuncType, x: T): T;
function tempTag1<T>(templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T;
function tempTag1<T>(...rest: any[]): T {
return undefined;
}
// If contextual typing takes place, these functions should work.
// Otherwise, the arrow functions' parameters will be typed as 'any',
// and it is an error to invoke an any-typed value with type arguments,
// so this test will error.
tempTag1 `${ x => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ 10 }`;
tempTag1 `${ x => { x<number>(undefined); return x; } }${ (y: <T>(p: T) => T) => { y<number>(undefined); return y } }${ undefined }`;
tempTag1 `${ (x: <T>(p: T) => T) => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ undefined }`;
//// [taggedTemplateContextualTyping1.js]
function tempTag1() {
var rest = [];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i - 0] = arguments[_i];
}
return undefined;
}
// If contextual typing takes place, these functions should work.
// Otherwise, the arrow functions' parameters will be typed as 'any',
// and it is an error to invoke an any-typed value with type arguments,
// so this test will error.
tempTag1 `${function (x) {
x(undefined);
return x;
}}${function (y) {
y(undefined);
return y;
}}${10}`;
tempTag1 `${function (x) {
x(undefined);
return x;
}}${function (y) {
y(undefined);
return y;
}}${undefined}`;
tempTag1 `${function (x) {
x(undefined);
return x;
}}${function (y) {
y(undefined);
return y;
}}${undefined}`;
@@ -0,0 +1,104 @@
=== tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts ===
type FuncType = (x: <T>(p: T) => T) => typeof x;
>FuncType : (x: <T>(p: T) => T) => <T>(p: T) => T
>x : <T>(p: T) => T
>T : T
>p : T
>T : T
>T : T
>x : <T>(p: T) => T
function tempTag1<T>(templateStrs: TemplateStringsArray, f: FuncType, x: T): T;
>tempTag1 : { <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, h: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; }
>T : T
>templateStrs : TemplateStringsArray
>TemplateStringsArray : TemplateStringsArray
>f : (x: <T>(p: T) => T) => <T>(p: T) => T
>FuncType : (x: <T>(p: T) => T) => <T>(p: T) => T
>x : T
>T : T
>T : T
function tempTag1<T>(templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T;
>tempTag1 : { <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, h: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; }
>T : T
>templateStrs : TemplateStringsArray
>TemplateStringsArray : TemplateStringsArray
>f : (x: <T>(p: T) => T) => <T>(p: T) => T
>FuncType : (x: <T>(p: T) => T) => <T>(p: T) => T
>h : (x: <T>(p: T) => T) => <T>(p: T) => T
>FuncType : (x: <T>(p: T) => T) => <T>(p: T) => T
>x : T
>T : T
>T : T
function tempTag1<T>(...rest: any[]): T {
>tempTag1 : { <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, h: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; }
>T : T
>rest : any[]
>T : T
return undefined;
>undefined : undefined
}
// If contextual typing takes place, these functions should work.
// Otherwise, the arrow functions' parameters will be typed as 'any',
// and it is an error to invoke an any-typed value with type arguments,
// so this test will error.
tempTag1 `${ x => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ 10 }`;
>tempTag1 : { <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, h: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; }
>x => { x<number>(undefined); return x; } : (x: <T>(p: T) => T) => <T>(p: T) => T
>x : <T>(p: T) => T
>x<number>(undefined) : number
>x : <T>(p: T) => T
>undefined : undefined
>x : <T>(p: T) => T
>y => { y<number>(undefined); return y; } : (y: <T>(p: T) => T) => <T>(p: T) => T
>y : <T>(p: T) => T
>y<number>(undefined) : number
>y : <T>(p: T) => T
>undefined : undefined
>y : <T>(p: T) => T
tempTag1 `${ x => { x<number>(undefined); return x; } }${ (y: <T>(p: T) => T) => { y<number>(undefined); return y } }${ undefined }`;
>tempTag1 : { <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, h: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; }
>x => { x<number>(undefined); return x; } : (x: <T>(p: T) => T) => <T>(p: T) => T
>x : <T>(p: T) => T
>x<number>(undefined) : number
>x : <T>(p: T) => T
>undefined : undefined
>x : <T>(p: T) => T
>(y: <T>(p: T) => T) => { y<number>(undefined); return y } : (y: <T>(p: T) => T) => <T>(p: T) => T
>y : <T>(p: T) => T
>T : T
>p : T
>T : T
>T : T
>y<number>(undefined) : number
>y : <T>(p: T) => T
>undefined : undefined
>y : <T>(p: T) => T
>undefined : undefined
tempTag1 `${ (x: <T>(p: T) => T) => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ undefined }`;
>tempTag1 : { <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, h: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; }
>(x: <T>(p: T) => T) => { x<number>(undefined); return x; } : (x: <T>(p: T) => T) => <T>(p: T) => T
>x : <T>(p: T) => T
>T : T
>p : T
>T : T
>T : T
>x<number>(undefined) : number
>x : <T>(p: T) => T
>undefined : undefined
>x : <T>(p: T) => T
>y => { y<number>(undefined); return y; } : (y: <T>(p: T) => T) => <T>(p: T) => T
>y : <T>(p: T) => T
>y<number>(undefined) : number
>y : <T>(p: T) => T
>undefined : undefined
>y : <T>(p: T) => T
>undefined : undefined
@@ -0,0 +1,46 @@
//// [taggedTemplateContextualTyping2.ts]
type FuncType1 = (x: <T>(p: T) => T) => typeof x;
type FuncType2 = (x: <S, T>(p: T) => T) => typeof x;
function tempTag2(templateStrs: TemplateStringsArray, f: FuncType1, x: number): number;
function tempTag2(templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string;
function tempTag2(...rest: any[]): any {
return undefined;
}
// If contextual typing takes place, these functions should work.
// Otherwise, the arrow functions' parameters will be typed as 'any',
// and it is an error to invoke an any-typed value with type arguments,
// so this test will error.
tempTag2 `${ x => { x<number>(undefined); return x; } }${ 0 }`;
tempTag2 `${ x => { x<number, string>(undefined); return x; } }${ y => { y<string, number>(null); return y; } }${ "hello" }`;
tempTag2 `${ x => { x<number, string>(undefined); return x; } }${ undefined }${ "hello" }`;
//// [taggedTemplateContextualTyping2.js]
function tempTag2() {
var rest = [];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i - 0] = arguments[_i];
}
return undefined;
}
// If contextual typing takes place, these functions should work.
// Otherwise, the arrow functions' parameters will be typed as 'any',
// and it is an error to invoke an any-typed value with type arguments,
// so this test will error.
tempTag2 `${function (x) {
x(undefined);
return x;
}}${0}`;
tempTag2 `${function (x) {
x(undefined);
return x;
}}${function (y) {
y(null);
return y;
}}${"hello"}`;
tempTag2 `${function (x) {
x(undefined);
return x;
}}${undefined}${"hello"}`;
@@ -0,0 +1,84 @@
=== tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping2.ts ===
type FuncType1 = (x: <T>(p: T) => T) => typeof x;
>FuncType1 : (x: <T>(p: T) => T) => <T>(p: T) => T
>x : <T>(p: T) => T
>T : T
>p : T
>T : T
>T : T
>x : <T>(p: T) => T
type FuncType2 = (x: <S, T>(p: T) => T) => typeof x;
>FuncType2 : (x: <S, T>(p: T) => T) => <S, T>(p: T) => T
>x : <S, T>(p: T) => T
>S : S
>T : T
>p : T
>T : T
>T : T
>x : <S, T>(p: T) => T
function tempTag2(templateStrs: TemplateStringsArray, f: FuncType1, x: number): number;
>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, h: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, x: string): string; }
>templateStrs : TemplateStringsArray
>TemplateStringsArray : TemplateStringsArray
>f : (x: <T>(p: T) => T) => <T>(p: T) => T
>FuncType1 : (x: <T>(p: T) => T) => <T>(p: T) => T
>x : number
function tempTag2(templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string;
>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, h: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, x: string): string; }
>templateStrs : TemplateStringsArray
>TemplateStringsArray : TemplateStringsArray
>f : (x: <S, T>(p: T) => T) => <S, T>(p: T) => T
>FuncType2 : (x: <S, T>(p: T) => T) => <S, T>(p: T) => T
>h : (x: <S, T>(p: T) => T) => <S, T>(p: T) => T
>FuncType2 : (x: <S, T>(p: T) => T) => <S, T>(p: T) => T
>x : string
function tempTag2(...rest: any[]): any {
>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, h: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, x: string): string; }
>rest : any[]
return undefined;
>undefined : undefined
}
// If contextual typing takes place, these functions should work.
// Otherwise, the arrow functions' parameters will be typed as 'any',
// and it is an error to invoke an any-typed value with type arguments,
// so this test will error.
tempTag2 `${ x => { x<number>(undefined); return x; } }${ 0 }`;
>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, h: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, x: string): string; }
>x => { x<number>(undefined); return x; } : (x: <T>(p: T) => T) => <T>(p: T) => T
>x : <T>(p: T) => T
>x<number>(undefined) : number
>x : <T>(p: T) => T
>undefined : undefined
>x : <T>(p: T) => T
tempTag2 `${ x => { x<number, string>(undefined); return x; } }${ y => { y<string, number>(null); return y; } }${ "hello" }`;
>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, h: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, x: string): string; }
>x => { x<number, string>(undefined); return x; } : (x: <S, T>(p: T) => T) => <S, T>(p: T) => T
>x : <S, T>(p: T) => T
>x<number, string>(undefined) : string
>x : <S, T>(p: T) => T
>undefined : undefined
>x : <S, T>(p: T) => T
>y => { y<string, number>(null); return y; } : (y: <S, T>(p: T) => T) => <S, T>(p: T) => T
>y : <S, T>(p: T) => T
>y<string, number>(null) : number
>y : <S, T>(p: T) => T
>y : <S, T>(p: T) => T
tempTag2 `${ x => { x<number, string>(undefined); return x; } }${ undefined }${ "hello" }`;
>tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, h: (x: <S, T>(p: T) => T) => <S, T>(p: T) => T, x: string): string; }
>x => { x<number, string>(undefined); return x; } : (x: <S, T>(p: T) => T) => <S, T>(p: T) => T
>x : <S, T>(p: T) => T
>x<number, string>(undefined) : string
>x : <S, T>(p: T) => T
>undefined : undefined
>x : <S, T>(p: T) => T
>undefined : undefined
@@ -0,0 +1,15 @@
tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts(6,5): error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher.
tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts(6,31): error TS2322: Type 'string' is not assignable to type 'number'.
==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts (2 errors) ====
function foo(...rest: any[]) {
}
foo `${function (x: number) { x = "bad"; } }`;
~~~
!!! error TS1159: Tagged templates are only available when targeting ECMAScript 6 and higher.
~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
@@ -0,0 +1,11 @@
tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts(5,31): error TS2322: Type 'string' is not assignable to type 'number'.
==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts (1 errors) ====
function foo(...rest: any[]) {
}
foo `${function (x: number) { x = "bad"; } }`;
~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
@@ -0,0 +1,17 @@
//// [taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts]
function foo(...rest: any[]) {
}
foo `${function (x: number) { x = "bad"; } }`;
//// [taggedTemplateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js]
function foo() {
var rest = [];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i - 0] = arguments[_i];
}
}
foo `${function (x) {
x = "bad";
}}`;
@@ -0,0 +1,9 @@
tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts(3,27): error TS2322: Type 'string' is not assignable to type 'number'.
==== tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts (1 errors) ====
`${function (x: number) { x = "bad"; } }`;
~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
@@ -0,0 +1,9 @@
//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.ts]
`${function (x: number) { x = "bad"; } }`;
//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpression.js]
"" + function (x) {
x = "bad";
};
@@ -0,0 +1,8 @@
tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts(2,27): error TS2322: Type 'string' is not assignable to type 'number'.
==== tests/cases/conformance/es6/templates/templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts (1 errors) ====
`${function (x: number) { x = "bad"; } }`;
~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
@@ -0,0 +1,8 @@
//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.ts]
`${function (x: number) { x = "bad"; } }`;
//// [templateStringsWithTypeErrorInFunctionExpressionsInSubstitutionExpressionES6.js]
`${function (x) {
x = "bad";
}}`;
@@ -0,0 +1,6 @@
function foo(...rest: any[]) {
}
foo `${function (x: number) { x = "bad"; } }`;
@@ -0,0 +1,6 @@
//@target: es6
function foo(...rest: any[]) {
}
foo `${function (x: number) { x = "bad"; } }`;
@@ -0,0 +1,3 @@
`${function (x: number) { x = "bad"; } }`;
@@ -0,0 +1,3 @@
//@target: es6
`${function (x: number) { x = "bad"; } }`;
@@ -0,0 +1,17 @@
// @target: ES6
type FuncType = (x: <T>(p: T) => T) => typeof x;
function tempTag1<T>(templateStrs: TemplateStringsArray, f: FuncType, x: T): T;
function tempTag1<T>(templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T;
function tempTag1<T>(...rest: any[]): T {
return undefined;
}
// If contextual typing takes place, these functions should work.
// Otherwise, the arrow functions' parameters will be typed as 'any',
// and it is an error to invoke an any-typed value with type arguments,
// so this test will error.
tempTag1 `${ x => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ 10 }`;
tempTag1 `${ x => { x<number>(undefined); return x; } }${ (y: <T>(p: T) => T) => { y<number>(undefined); return y } }${ undefined }`;
tempTag1 `${ (x: <T>(p: T) => T) => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ undefined }`;
@@ -0,0 +1,18 @@
// @target: ES6
type FuncType1 = (x: <T>(p: T) => T) => typeof x;
type FuncType2 = (x: <S, T>(p: T) => T) => typeof x;
function tempTag2(templateStrs: TemplateStringsArray, f: FuncType1, x: number): number;
function tempTag2(templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string;
function tempTag2(...rest: any[]): any {
return undefined;
}
// If contextual typing takes place, these functions should work.
// Otherwise, the arrow functions' parameters will be typed as 'any',
// and it is an error to invoke an any-typed value with type arguments,
// so this test will error.
tempTag2 `${ x => { x<number>(undefined); return x; } }${ 0 }`;
tempTag2 `${ x => { x<number, string>(undefined); return x; } }${ y => { y<string, number>(null); return y; } }${ "hello" }`;
tempTag2 `${ x => { x<number, string>(undefined); return x; } }${ undefined }${ "hello" }`;
@@ -0,0 +1,19 @@
/// <reference path="fourslash.ts" />
////function tempTag1<T>(templateStrs: TemplateStringsArray, f: (x: T) => T, x: T): T;
////function tempTag1<T>(templateStrs: TemplateStringsArray, f: (x: T) => T, h: (y: T) => T, x: T): T;
////function tempTag1<T>(...rest: any[]): T {
//// return undefined;
////}
////
////tempTag1 `${ x => /*0*/x }${ 10 }`;
////tempTag1 `${ x => /*1*/x }${ x => /*2*/x }${ 10 }`;
////tempTag1 `${ x => /*3*/x }${ (x: number) => /*4*/x }${ undefined }`;
////tempTag1 `${ (x: number) => /*5*/x }${ x => /*6*/x }${ undefined }`;
var markers = test.markers();
markers.forEach(marker => {
goTo.position(marker.position);
verify.quickInfoIs("(parameter) x: number");
});
@@ -0,0 +1,31 @@
/// <reference path="fourslash.ts" />
////function tempTag2(templateStrs: TemplateStringsArray, f: (x: number) => number, x: number): number;
////function tempTag2(templateStrs: TemplateStringsArray, f: (x: string) => string, h: (y: string) => string, x: string): string;
////function tempTag2(...rest: any[]): any {
//// return undefined;
////}
////
////tempTag2 `${ x => /*0*/x }${ 0 }`;
////tempTag2 `${ /*1*/x => /*2*/x }${ undefined }`;
////tempTag2 `${ x => /*3*/x }${ x => /*4*/x }${ "hello" }`;
////tempTag2 `${ x => /*5*/x }${ undefined }${ "hello" }`;
// The first group of parameters, [0, 2], should all be contextually typed as 'number'.
// The second group, [3, 5], should be typed as 'string'.
var numTypedVariableCount = 3;
var strTypedVariableCount = 3;
if (numTypedVariableCount + strTypedVariableCount !== test.markers().length) {
throw "Unexpected number of markers in file.";
}
for (var i = 0; i < numTypedVariableCount; i++) {
goTo.marker("" + i);
verify.quickInfoIs("(parameter) x: number");
}
for (var i = 0; i < strTypedVariableCount; i++) {
goTo.marker("" + (i + numTypedVariableCount));
verify.quickInfoIs("(parameter) x: string");
}