diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 56dc73237f3..38a0cb80797 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2066,7 +2066,7 @@ module ts { } function resolveTupleTypeMembers(type: TupleType) { - var arrayType = resolveObjectTypeMembers(createArrayType(getBestCommonType(type.elementTypes))); + var arrayType = resolveObjectTypeMembers(createArrayType(getUnionType(type.elementTypes))); var members = createTupleTypeMemberSymbols(type.elementTypes); addInheritedMembers(members, arrayType.properties); setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType); @@ -2724,13 +2724,41 @@ module ts { } } - function getUnionType(types: Type[]): Type { + function containsAnyType(types: Type[]) { + for (var i = 0; i < types.length; i++) { + if (types[i].flags & TypeFlags.Any) { + return true; + } + } + return false; + } + + function removeAllButLast(types: Type[], typeToRemove: Type) { + var i = types.length; + while (i > 0 && types.length > 1) { + i--; + if (types[i] === typeToRemove) { + types.splice(i, 1); + } + } + } + + function getUnionType(types: Type[], noSubtypeReduction?: boolean): Type { if (types.length === 0) { return emptyObjectType; } var sortedTypes: Type[] = []; addTypesToSortedSet(sortedTypes, types); - removeSubtypes(sortedTypes); + if (noSubtypeReduction) { + if (containsAnyType(sortedTypes)) { + return anyType; + } + removeAllButLast(sortedTypes, undefinedType); + removeAllButLast(sortedTypes, nullType); + } + else { + removeSubtypes(sortedTypes); + } if (sortedTypes.length === 1) { return sortedTypes[0]; } @@ -2746,7 +2774,7 @@ module ts { function getTypeFromUnionTypeNode(node: UnionTypeNode): Type { var links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode)); + links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true); } return links.resolvedType; } @@ -2964,7 +2992,7 @@ module ts { return createTupleType(instantiateList((type).elementTypes, mapper, instantiateType)); } if (type.flags & TypeFlags.Union) { - return getUnionType(instantiateList((type).types, mapper, instantiateType)); + return getUnionType(instantiateList((type).types, mapper, instantiateType), /*noSubtypeReduction*/ true); } } return type; @@ -3614,7 +3642,7 @@ module ts { return forEach(types, t => isSupertypeOfEach(t, types) ? t : undefined); } - function getBestCommonType(types: Type[], contextualType?: Type): Type { + function getBestCommonType(types: Type[], contextualType: Type): Type { return contextualType && isSupertypeOfEach(contextualType, types) ? contextualType : getUnionType(types); } @@ -4567,7 +4595,7 @@ module ts { return createTupleType(elementTypes); } var contextualElementType = contextualType && !isInferentialContext(contextualMapper) ? getIndexTypeOfType(contextualType, IndexKind.Number) : undefined; - var elementType = elements.length || contextualElementType ? getBestCommonType(deduplicate(elementTypes), contextualElementType) : undefinedType; + var elementType = elements.length || contextualElementType ? getBestCommonType(elementTypes, contextualElementType) : undefinedType; return createArrayType(elementType); } @@ -5610,7 +5638,7 @@ module ts { case SyntaxKind.AmpersandAmpersandToken: return rightType; case SyntaxKind.BarBarToken: - return getBestCommonType([leftType, rightType], isInferentialContext(contextualMapper) ? undefined : getContextualType(node)); + return getUnionType([leftType, rightType]); case SyntaxKind.EqualsToken: checkAssignmentOperator(rightType); return rightType; @@ -5660,9 +5688,7 @@ module ts { checkExpression(node.condition); var type1 = checkExpression(node.whenTrue, contextualMapper); var type2 = checkExpression(node.whenFalse, contextualMapper); - var contextualType = isInferentialContext(contextualMapper) ? undefined : getContextualType(node); - var resultType = getBestCommonType([type1, type2], contextualType); - return resultType; + return getUnionType([type1, type2]); } function checkExpressionWithContextualType(node: Expression, contextualType: Type, contextualMapper?: TypeMapper): Type { diff --git a/tests/baselines/reference/aliasUsageInOrExpression.types b/tests/baselines/reference/aliasUsageInOrExpression.types index fdcf0be4479..c937187f049 100644 --- a/tests/baselines/reference/aliasUsageInOrExpression.types +++ b/tests/baselines/reference/aliasUsageInOrExpression.types @@ -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 diff --git a/tests/baselines/reference/arrayBestCommonTypes.js b/tests/baselines/reference/arrayBestCommonTypes.js index 675d84119c0..f8e158e5b02 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.js +++ b/tests/baselines/reference/arrayBestCommonTypes.js @@ -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() { - (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])); + 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; } - (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])); + public x() { + (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([[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() } ]; + (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])); - 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(); + (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() { + (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: 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 = {})); diff --git a/tests/baselines/reference/arrayBestCommonTypes.types b/tests/baselines/reference/arrayBestCommonTypes.types index 6495b7df6a6..a2a6921ca4e 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.types +++ b/tests/baselines/reference/arrayBestCommonTypes.types @@ -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 - (this.voidIfAny([4, 2][0])); + (this.voidIfAny([4, 2][0])); >(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[] - (this.voidIfAny([4, 2, undefined][0])); + (this.voidIfAny([4, 2, undefined][0])); >(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 - (this.voidIfAny([undefined, 2, 4][0])); + (this.voidIfAny([undefined, 2, 4][0])); >(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 - (this.voidIfAny([null, 2, 4][0])); + (this.voidIfAny([null, 2, 4][0])); >(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[] - (this.voidIfAny([2, 4, null][0])); + (this.voidIfAny([2, 4, null][0])); >(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[] - (this.voidIfAny([undefined, 4, null][0])); + (this.voidIfAny([undefined, 4, null][0])); >(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 - (this.voidIfAny(['', "q"][0])); + (this.voidIfAny(['', "q"][0])); >(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[] - (this.voidIfAny(['', "q", undefined][0])); + (this.voidIfAny(['', "q", undefined][0])); >(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 - (this.voidIfAny([undefined, "q", ''][0])); + (this.voidIfAny([undefined, "q", ''][0])); >(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 - (this.voidIfAny([null, "q", ''][0])); + (this.voidIfAny([null, "q", ''][0])); >(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[] - (this.voidIfAny(["q", '', null][0])); + (this.voidIfAny(["q", '', null][0])); >(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[] - (this.voidIfAny([undefined, '', null][0])); + (this.voidIfAny([undefined, '', null][0])); >(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 - (this.voidIfAny([[3,4],[null]][0][0])); ->(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])); +>(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: base; }[] >{ 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: base; }[] >{ 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: base; }[] >{ 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 ]; + var b1 = [baseObj, base2Obj, ifaceObj]; >b1 : iface[] ->[ baseObj, base2Obj, ifaceObj ] : iface[] +>[baseObj, base2Obj, ifaceObj] : iface[] >baseObj : base >base2Obj : base2 >ifaceObj : iface - var b2 = [ base2Obj, baseObj, ifaceObj ]; + var b2 = [base2Obj, baseObj, ifaceObj]; >b2 : iface[] ->[ base2Obj, baseObj, ifaceObj ] : iface[] +>[base2Obj, baseObj, ifaceObj] : iface[] >base2Obj : base2 >baseObj : base >ifaceObj : iface - var b3 = [ baseObj, ifaceObj, base2Obj ]; + var b3 = [baseObj, ifaceObj, base2Obj]; >b3 : iface[] ->[ baseObj, ifaceObj, base2Obj ] : 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 + + (this.voidIfAny([4, 2][0])); +>(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[] + + (this.voidIfAny([4, 2, undefined][0])); +>(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 + + (this.voidIfAny([undefined, 2, 4][0])); +>(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 + + (this.voidIfAny([null, 2, 4][0])); +>(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[] + + (this.voidIfAny([2, 4, null][0])); +>(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[] + + (this.voidIfAny([undefined, 4, null][0])); +>(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 + + (this.voidIfAny(['', "q"][0])); +>(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[] + + (this.voidIfAny(['', "q", undefined][0])); +>(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 + + (this.voidIfAny([undefined, "q", ''][0])); +>(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 + + (this.voidIfAny([null, "q", ''][0])); +>(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[] + + (this.voidIfAny(["q", '', null][0])); +>(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[] + + (this.voidIfAny([undefined, '', null][0])); +>(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 + + (this.voidIfAny([[3, 4], [null]][0][0])); +>(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() }] : { x: string; y: base; }[] +>{ 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 + } } } - diff --git a/tests/baselines/reference/arrayLiteralContextualType.js b/tests/baselines/reference/arrayLiteralContextualType.js index a551a754204..65e4c135cba 100644 --- a/tests/baselines/reference/arrayLiteralContextualType.js +++ b/tests/baselines/reference/arrayLiteralContextualType.js @@ -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 not {}[] +bar(arr); // ok because arr is Array 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 not {}[] +bar(arr); // ok because arr is Array not {}[] diff --git a/tests/baselines/reference/arrayLiteralContextualType.types b/tests/baselines/reference/arrayLiteralContextualType.types index 3d5330d00c9..015a428c114 100644 --- a/tests/baselines/reference/arrayLiteralContextualType.types +++ b/tests/baselines/reference/arrayLiteralContextualType.types @@ -74,12 +74,12 @@ var arr = [new Giraffe(), new Elephant()]; >new Elephant() : Elephant >Elephant : typeof Elephant -foo(arr); // Error because of no contextual type +foo(arr); // ok because arr is Array not {}[] >foo(arr) : void >foo : (animals: IAnimal[]) => void >arr : Array -bar(arr); // Error because of no contextual type +bar(arr); // ok because arr is Array not {}[] >bar(arr) : void >bar : (animals: { [x: number]: IAnimal; }) => void >arr : Array diff --git a/tests/baselines/reference/arrayLiterals.errors.txt b/tests/baselines/reference/arrayLiterals.errors.txt deleted file mode 100644 index 65666a50ce8..00000000000 --- a/tests/baselines/reference/arrayLiterals.errors.txt +++ /dev/null @@ -1,56 +0,0 @@ -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(4,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr1' must be of type 'Array', but here has type '{}[]'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(7,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'Array', but here has type '{}[]'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(33,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'context2' must be of type 'Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }>', but here has type '{}[]'. - - -==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts (3 errors) ==== - // 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 - ~~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr1' must be of type 'Array', but here has type '{}[]'. - - var arr2 = [[null], [1], ['']]; - var arr2: {}[]; // Bug 825172: Error ({}[] does not match {}[]), but should be OK - ~~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'Array', but here has type '{}[]'. - - - // 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; // 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 - ~~~~~~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'context2' must be of type 'Array<{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }>', but here has type '{}[]'. - - // Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] - class Base { private p; } - class Derived1 extends Base { private m }; - class Derived2 extends Base { private n }; - var context3: Base[] = [new Derived1(), new Derived2()]; - - // Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[] - var context4: Base[] = [new Derived1(), new Derived1()]; - - \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals.js b/tests/baselines/reference/arrayLiterals.js index 800d2a12550..16e5ec7eee4 100644 --- a/tests/baselines/reference/arrayLiterals.js +++ b/tests/baselines/reference/arrayLiterals.js @@ -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; // Should OK, not be a parse error @@ -31,7 +24,6 @@ var classTypeArray: Array; // 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() { diff --git a/tests/baselines/reference/arrayLiterals.types b/tests/baselines/reference/arrayLiterals.types new file mode 100644 index 00000000000..d66e9d741a9 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals.types @@ -0,0 +1,124 @@ +=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts === +// Empty array literal with no contextual type has type Undefined[] + +var arr1= [[], [1], ['']]; +>arr1 : Array +>[[], [1], ['']] : Array +>[] : undefined[] +>[1] : number[] +>[''] : string[] + +var arr2 = [[null], [1], ['']]; +>arr2 : Array +>[[null], [1], ['']] : Array +>[null] : null[] +>[1] : number[] +>[''] : string[] + + +// Array literal with elements of only EveryType E has type E[] +var stringArrArr = [[''], [""]]; +>stringArrArr : string[][] +>[[''], [""]] : string[][] +>[''] : string[] +>[""] : string[] + +var stringArr = ['', ""]; +>stringArr : string[] +>['', ""] : string[] + +var numberArr = [0, 0.0, 0x00, 1e1]; +>numberArr : number[] +>[0, 0.0, 0x00, 1e1] : number[] + +var boolArr = [false, true, false, true]; +>boolArr : boolean[] +>[false, true, false, true] : boolean[] + +class C { private p; } +>C : C +>p : any + +var classArr = [new C(), new C()]; +>classArr : C[] +>[new C(), new C()] : C[] +>new C() : C +>C : typeof C +>new C() : C +>C : typeof C + +var classTypeArray = [C, C, C]; +>classTypeArray : typeof C[] +>[C, C, C] : typeof C[] +>C : typeof C +>C : typeof C +>C : typeof C + +var classTypeArray: Array; // Should OK, not be a parse error +>classTypeArray : typeof C[] +>Array : T[] +>C : typeof C + +// 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 }]; +>context1 : { [x: number]: { a: string; b: number; }; } +>n : number +>a : string +>b : number +>[{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }] : { a: string; b: number; }[] +>{ a: '', b: 0, c: '' } : { a: string; b: number; c: string; } +>a : string +>b : number +>c : string +>{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; } +>a : string +>b : number +>c : number + +var 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 +>c : string +>{ a: "", b: 3, c: 0 } : { a: string; b: number; c: number; } +>a : string +>b : number +>c : number + +// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[] +class Base { private p; } +>Base : Base +>p : any + +class Derived1 extends Base { private m }; +>Derived1 : Derived1 +>Base : Base +>m : any + +class Derived2 extends Base { private n }; +>Derived2 : Derived2 +>Base : Base +>n : any + +var context3: Base[] = [new Derived1(), new Derived2()]; +>context3 : Base[] +>Base : Base +>[new Derived1(), new Derived2()] : Base[] +>new Derived1() : Derived1 +>Derived1 : typeof Derived1 +>new Derived2() : Derived2 +>Derived2 : typeof Derived2 + +// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[] +var context4: Base[] = [new Derived1(), new Derived1()]; +>context4 : Base[] +>Base : Base +>[new Derived1(), new Derived1()] : Base[] +>new Derived1() : Derived1 +>Derived1 : typeof Derived1 +>new Derived1() : Derived1 +>Derived1 : typeof Derived1 + + diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types index 18fe6efb8ce..2c3ba8bc7c7 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types @@ -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: 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 } diff --git a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types index 8ad918936d2..edef88acfc3 100644 --- a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types +++ b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types @@ -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 diff --git a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt index 33905a2cdad..fb2c02d1c28 100644 --- a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt +++ b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.errors.txt @@ -1,16 +1,16 @@ -tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts(16,5): error TS2322: Type 'A | B' is not assignable to type 'A': +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(17,5): error TS2322: Type 'A | B' is not assignable to 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(19,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => number': +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(20,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => string': +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(21,5): error TS2322: Type '{ (m: X): number; } | { (n: X): string; }' is not assignable to type '(t: X) => boolean': +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'. @@ -25,12 +25,11 @@ 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; 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; ~~~~~~~ !!! error TS2322: Type 'A | B' is not assignable to type 'A': diff --git a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js index 90125d4ebf6..b6376dd781f 100644 --- a/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js +++ b/tests/baselines/reference/conditionalOperatorWithoutIdenticalBCT.js @@ -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; }; diff --git a/tests/baselines/reference/contextualTypingOfConditionalExpression.types b/tests/baselines/reference/contextualTypingOfConditionalExpression.types index 6c6f9b04457..2cd2b671b40 100644 --- a/tests/baselines/reference/contextualTypingOfConditionalExpression.types +++ b/tests/baselines/reference/contextualTypingOfConditionalExpression.types @@ -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 diff --git a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt index b8cd56acadd..a524fd3be31 100644 --- a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt +++ b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.errors.txt @@ -4,9 +4,9 @@ tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,10): error TS ==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (2 errors) ==== var f10: (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. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js index cf7274db8a0..55f7580b3f8 100644 --- a/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js +++ b/tests/baselines/reference/contextualTypingWithFixedTypeParameters1.js @@ -1,9 +1,9 @@ //// [contextualTypingWithFixedTypeParameters1.ts] var f10: (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 diff --git a/tests/baselines/reference/contextuallyTypingOrOperator.types b/tests/baselines/reference/contextuallyTypingOrOperator.types index 5a20b2b921e..4b47ea763bc 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator.types @@ -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 diff --git a/tests/baselines/reference/contextuallyTypingOrOperator2.types b/tests/baselines/reference/contextuallyTypingOrOperator2.types index b46d0c0aedb..c233066d6dc 100644 --- a/tests/baselines/reference/contextuallyTypingOrOperator2.types +++ b/tests/baselines/reference/contextuallyTypingOrOperator2.types @@ -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 diff --git a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt index c03b31e9e27..21296783f28 100644 --- a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt +++ b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.errors.txt @@ -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(16,14): error TS2346: Supplied parameters do not match any signature of call target. +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(x: T, y: T): T { return null; } - - var result = concat(1, ""); + var result = concat(1, ""); // error ~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. + var elementCount = result.length; + + function concat2(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 \ No newline at end of file diff --git a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js index 59935cc53af..98e135cc712 100644 --- a/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js +++ b/tests/baselines/reference/defaultBestCommonTypesHaveDecls.js @@ -1,22 +1,18 @@ //// [defaultBestCommonTypesHaveDecls.ts] - var obj1: {}; - obj1.length; - - var obj2: Object; - obj2.length; - - function concat(x: T, y: T): T { return null; } +var result = concat(1, ""); // error +var elementCount = result.length; -var result = concat(1, ""); +function concat2(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; diff --git a/tests/baselines/reference/generatedContextualTyping.types b/tests/baselines/reference/generatedContextualTyping.types index c609c6aec9c..658d4a0bff1 100644 --- a/tests/baselines/reference/generatedContextualTyping.types +++ b/tests/baselines/reference/generatedContextualTyping.types @@ -2616,7 +2616,7 @@ var x267: { [n: number]: Base; } = [d1, d2] || undefined; >x267 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] || undefined : { [x: number]: Base; } +>[d1, d2] || undefined : Base[] >[d1, d2] : Base[] >d1 : Derived1 >d2 : Derived2 @@ -2699,7 +2699,7 @@ var x275: { [n: number]: Base; } = undefined || [d1, d2]; >x275 : { [x: number]: Base; } >n : number >Base : Base ->undefined || [d1, d2] : { [x: number]: Base; } +>undefined || [d1, d2] : Base[] >undefined : undefined >[d1, d2] : Base[] >d1 : Derived1 @@ -2800,7 +2800,7 @@ var x283: { [n: number]: Base; } = [d1, d2] || [d1, d2]; >x283 : { [x: number]: Base; } >n : number >Base : Base ->[d1, d2] || [d1, d2] : { [x: number]: Base; } +>[d1, d2] || [d1, d2] : Base[] >[d1, d2] : Base[] >d1 : Derived1 >d2 : Derived2 @@ -2933,7 +2933,7 @@ var x293: { [n: number]: Base; } = true ? [d1, d2] : [d1, d2]; >x293 : { [x: number]: Base; } >n : number >Base : Base ->true ? [d1, d2] : [d1, d2] : { [x: number]: Base; } +>true ? [d1, d2] : [d1, d2] : Base[] >[d1, d2] : Base[] >d1 : Derived1 >d2 : Derived2 @@ -2961,7 +2961,7 @@ var x295: (s: Base[]) => any = true ? n => { var n: Base[]; return null; } : n = >x295 : (s: Base[]) => any >s : Base[] >Base : Base ->true ? n => { var n: Base[]; return null; } : n => { var n: Base[]; return null; } : (s: Base[]) => any +>true ? n => { var n: Base[]; return null; } : n => { var n: Base[]; return null; } : (n: Base[]) => any >n => { var n: Base[]; return null; } : (n: Base[]) => any >n : Base[] >n : Base[] @@ -2975,7 +2975,7 @@ var x296: Genric = true ? { func: n => { return [d1, d2]; } } : { func: n >x296 : Genric >Genric : Genric >Base : Base ->true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } } : Genric +>true ? { func: n => { return [d1, d2]; } } : { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >func : (n: Base[]) => Array >n => { return [d1, d2]; } : (n: Base[]) => Array @@ -3076,7 +3076,7 @@ var x305: { [n: number]: Base; } = true ? undefined : [d1, d2]; >x305 : { [x: number]: Base; } >n : number >Base : Base ->true ? undefined : [d1, d2] : { [x: number]: Base; } +>true ? undefined : [d1, d2] : Base[] >undefined : undefined >[d1, d2] : Base[] >d1 : Derived1 @@ -3098,7 +3098,7 @@ var x307: (s: Base[]) => any = true ? undefined : n => { var n: Base[]; return n >x307 : (s: Base[]) => any >s : Base[] >Base : Base ->true ? undefined : n => { var n: Base[]; return null; } : (s: Base[]) => any +>true ? undefined : n => { var n: Base[]; return null; } : (n: Base[]) => any >undefined : undefined >n => { var n: Base[]; return null; } : (n: Base[]) => any >n : Base[] @@ -3109,7 +3109,7 @@ var x308: Genric = true ? undefined : { func: n => { return [d1, d2]; } }; >x308 : Genric >Genric : Genric >Base : Base ->true ? undefined : { func: n => { return [d1, d2]; } } : Genric +>true ? undefined : { func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >undefined : undefined >{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >func : (n: Base[]) => Array @@ -3204,7 +3204,7 @@ var x317: { [n: number]: Base; } = true ? [d1, d2] : undefined; >x317 : { [x: number]: Base; } >n : number >Base : Base ->true ? [d1, d2] : undefined : { [x: number]: Base; } +>true ? [d1, d2] : undefined : Base[] >[d1, d2] : Base[] >d1 : Derived1 >d2 : Derived2 @@ -3226,7 +3226,7 @@ var x319: (s: Base[]) => any = true ? n => { var n: Base[]; return null; } : und >x319 : (s: Base[]) => any >s : Base[] >Base : Base ->true ? n => { var n: Base[]; return null; } : undefined : (s: Base[]) => any +>true ? n => { var n: Base[]; return null; } : undefined : (n: Base[]) => any >n => { var n: Base[]; return null; } : (n: Base[]) => any >n : Base[] >n : Base[] @@ -3237,7 +3237,7 @@ var x320: Genric = true ? { func: n => { return [d1, d2]; } } : undefined; >x320 : Genric >Genric : Genric >Base : Base ->true ? { func: n => { return [d1, d2]; } } : undefined : Genric +>true ? { func: n => { return [d1, d2]; } } : undefined : { func: (n: Base[]) => Array; } >{ func: n => { return [d1, d2]; } } : { func: (n: Base[]) => Array; } >func : (n: Base[]) => Array >n => { return [d1, d2]; } : (n: Base[]) => Array diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt b/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt index 1a84c08dc32..36a22868333 100644 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments.errors.txt @@ -33,25 +33,25 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFun var r7 = foo3(1, (a: Z) => '', ''); // string - var r8 = foo3(1, function (a) { return '' }, 1); // {} + 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(1, (a) => '', ''); // string function other(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 ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var r10 = foo2(1, (x) => ''); // string - var r11 = foo3(1, (x: T) => '', ''); // 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); // {} + 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); // {} + 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'. diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments.js b/tests/baselines/reference/genericCallWithFunctionTypedArguments.js index 8e844cfbc5a..fed1d4ca990 100644 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments.js +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments.js @@ -24,16 +24,16 @@ function foo3(x: T, cb: (a: T) => U, y: U) { var r7 = foo3(1, (a: Z) => '', ''); // string -var r8 = foo3(1, function (a) { return '' }, 1); // {} +var r8 = foo3(1, function (a) { return '' }, 1); // error var r9 = foo3(1, (a) => '', ''); // string function other(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 } diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt index 6caeb1cd6d6..083d197bbb4 100644 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.errors.txt @@ -31,7 +31,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFun return new cb(x); } - var r4 = foo2(1, i2); // string, instantiated generic + var r4 = foo2(1, i2); // error ~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var r4b = foo2(1, a); // any @@ -44,7 +44,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFun 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 ~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var r9 = foo3('', i2, ''); // string \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js index ca9b79c3507..7e9b7886fb4 100644 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.js @@ -27,7 +27,7 @@ function foo2(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('', i2); // string @@ -38,7 +38,7 @@ function foo3(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('', 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 diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt index 1a4ad29fce8..55318f268bd 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.errors.txt @@ -1,54 +1,106 @@ -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts(9,25): error TS2346: Supplied parameters do not match any signature of call target. -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 (5 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(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; - } + module onlyT { + function foo(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(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(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(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; - } + function foo2(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } - function other3(x: T) { - var r7 = foo2((a: T) => a, (b: T) => b); // error - ~~~~~~~~~~~ + function other3(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(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(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } - function foo3(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'. \ No newline at end of file + function other2(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(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } + + function other3(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(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); + } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js index 7dc955b6172..7acdcc32536 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js @@ -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(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; +module onlyT { + function foo(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(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(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + function other3(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(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(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -function other2(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(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; -} + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); + var r9 = r7(new Date()); + var r10 = r7(1); + } -function other3(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(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -enum E { A } -enum F { A } + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); + var r7b = foo2((a) => a, (b) => b); + } -function foo3(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(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 = {})); diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt index 691a3f1192c..0a42d940625 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt @@ -34,9 +34,9 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen 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 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); // (string => boolean) => {} + 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. \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js index 8ffb4f9970b..ca28878daa3 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js @@ -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 diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt b/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt index 092540b4994..856f35a57f6 100644 --- a/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt +++ b/tests/baselines/reference/genericCallWithObjectLiteralArgs.errors.txt @@ -6,7 +6,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObj return x; } - var r = foo({ bar: 1, baz: '' }); // T = {} + 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 diff --git a/tests/baselines/reference/genericCallWithObjectLiteralArgs.js b/tests/baselines/reference/genericCallWithObjectLiteralArgs.js index 84a630425be..2515bbef293 100644 --- a/tests/baselines/reference/genericCallWithObjectLiteralArgs.js +++ b/tests/baselines/reference/genericCallWithObjectLiteralArgs.js @@ -3,7 +3,7 @@ function foo(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({ bar: 1, baz: '' }); // T = Object @@ -12,7 +12,7 @@ var r4 = foo({ 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 diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types index 6c8ed4e468a..aa1eeaf4670 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgs2.types +++ b/tests/baselines/reference/genericCallWithObjectTypeArgs2.types @@ -57,7 +57,7 @@ var r = f({ x: new Derived(), y: new Derived2() }); // {}[] var r2 = f({ x: new Base(), y: new Derived2() }); // {}[] >r2 : Base[] ->f({ x: new Base(), y: new Derived2() }) : Base[] +>f({ x: new Base(), y: new Derived2() }) : Array >f : (a: { x: T; y: U; }) => Array >{ x: new Base(), y: new Derived2() } : { x: Base; y: Derived2; } >x : Base diff --git a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt index b5a423ac07b..3ddb094970a 100644 --- a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt +++ b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.errors.txt @@ -37,7 +37,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOve return cb; } - var r8 = foo6(a); // new{} => string; new(x:{}, y?:{}) => string + 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 diff --git a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js index 9da34ebad86..4f74b043bd9 100644 --- a/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js +++ b/tests/baselines/reference/genericCallWithOverloadedConstructorTypedArguments.js @@ -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(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; diff --git a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt index 63ac5002f8a..30ed4bc431f 100644 --- a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt +++ b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.errors.txt @@ -62,18 +62,18 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFu var c3: C3; function other(t: T, u: U) { - var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = c.foo2(1, (x: T) => ''); // error ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var r10 = c.foo2(1, (x) => ''); // string - var r11 = c3.foo3(1, (x: T) => '', ''); // string + var r11 = c3.foo3(1, (x: T) => '', ''); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. - var r11b = c3.foo3(1, (x: T) => '', 1); // {} + var r11b = c3.foo3(1, (x: T) => '', 1); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. - var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} + var r12 = c3.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'. diff --git a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js index 1af5f0ea6e6..7ec25949534 100644 --- a/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js +++ b/tests/baselines/reference/genericClassWithFunctionTypedMemberArguments.js @@ -55,12 +55,12 @@ module WithCandidates { var c3: C3; function other(t: T, u: U) { - var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = c.foo2(1, (x: T) => ''); // error var r10 = c.foo2(1, (x) => ''); // string - var r11 = c3.foo3(1, (x: T) => '', ''); // string - var r11b = c3.foo3(1, (x: T) => '', 1); // {} - var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} + var r11 = c3.foo3(1, (x: T) => '', ''); // error + var r11b = c3.foo3(1, (x: T) => '', 1); // error + var r12 = c3.foo3(1, function (a) { return '' }, 1); // error } } @@ -132,12 +132,12 @@ var WithCandidates; })(); var c3; function other(t, u) { - var r10 = c.foo2(1, function (x) { return ''; }); // string, non-generic signature allows inferences to be made + var r10 = c.foo2(1, function (x) { return ''; }); // error var r10 = c.foo2(1, function (x) { return ''; }); // string - var r11 = c3.foo3(1, function (x) { return ''; }, ''); // string - var r11b = c3.foo3(1, function (x) { return ''; }, 1); // {} + var r11 = c3.foo3(1, function (x) { return ''; }, ''); // error + var r11b = c3.foo3(1, function (x) { return ''; }, 1); // error var r12 = c3.foo3(1, function (a) { return ''; - }, 1); // {} + }, 1); // error } })(WithCandidates || (WithCandidates = {})); diff --git a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types index d44b220e818..95c9643c29a 100644 --- a/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types +++ b/tests/baselines/reference/logicalOrExpressionIsContextuallyTyped.types @@ -7,7 +7,7 @@ var r: { a: string } = { a: '', b: 123 } || { a: '', b: true }; >r : { a: string; } >a : string ->{ a: '', b: 123 } || { a: '', b: true } : { a: string; } +>{ a: '', b: 123 } || { a: '', b: true } : { a: string; b: number; } | { a: string; b: boolean; } >{ a: '', b: 123 } : { a: string; b: number; } >a : string >b : number diff --git a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types index 9a450b87784..4008fbbff50 100644 --- a/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types +++ b/tests/baselines/reference/logicalOrOperatorWithTypeParameters.types @@ -29,7 +29,7 @@ function fn1(t: T, u: U) { var r4: {} = t || u; >r4 : {} ->t || u : {} +>t || u : T | U >t : T >u : U } @@ -74,7 +74,7 @@ function fn2(t: T, u: U, v: V) { var r6: {} = u || v; >r6 : {} ->u || v : {} +>u || v : U | V >u : U >v : V @@ -102,7 +102,7 @@ function fn3r2 : {} ->t || u : {} +>t || u : T | U >t : T >u : U @@ -116,7 +116,7 @@ function fn3r4 : { a: string; } >a : string ->t || u : { a: string; } +>t || u : T | U >t : T >u : U } diff --git a/tests/baselines/reference/nonContextuallyTypedLogicalOr.js b/tests/baselines/reference/nonContextuallyTypedLogicalOr.js index a29390bcf7f..e3ec95533fd 100644 --- a/tests/baselines/reference/nonContextuallyTypedLogicalOr.js +++ b/tests/baselines/reference/nonContextuallyTypedLogicalOr.js @@ -12,13 +12,9 @@ interface Ellement { var c: Contextual; var e: Ellement; -// This should error. Even though we are contextually typing e with Contextual, the RHS still -// needs to be a supertype of the LHS to win as the best common type. (c || e).dummy; //// [nonContextuallyTypedLogicalOr.js] var c; var e; -// This should error. Even though we are contextually typing e with Contextual, the RHS still -// needs to be a supertype of the LHS to win as the best common type. (c || e).dummy; diff --git a/tests/baselines/reference/nonContextuallyTypedLogicalOr.types b/tests/baselines/reference/nonContextuallyTypedLogicalOr.types index 4d15083c3b7..aeb9d1409c6 100644 --- a/tests/baselines/reference/nonContextuallyTypedLogicalOr.types +++ b/tests/baselines/reference/nonContextuallyTypedLogicalOr.types @@ -27,8 +27,6 @@ var e: Ellement; >e : Ellement >Ellement : Ellement -// This should error. Even though we are contextually typing e with Contextual, the RHS still -// needs to be a supertype of the LHS to win as the best common type. (c || e).dummy; >(c || e).dummy : any >(c || e) : Contextual | Ellement diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index 4ee3ea31de6..0b2aa01bb5c 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -47,7 +47,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -107,7 +107,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); - var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); + var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error ~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number) => IPromise' is not assignable to parameter of type '(value: IPromise) => IPromise'. @@ -128,7 +128,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. - var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); + var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -222,7 +222,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok - var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + var s9f = s9.then(testFunction, sIPromise, nIPromise); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok @@ -241,23 +241,23 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; - var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok + var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. - var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok + var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. - var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok + var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. diff --git a/tests/baselines/reference/promisePermutations.js b/tests/baselines/reference/promisePermutations.js index 189ef40335e..e59e49d6f8c 100644 --- a/tests/baselines/reference/promisePermutations.js +++ b/tests/baselines/reference/promisePermutations.js @@ -12,7 +12,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -72,7 +72,7 @@ var s3: Promise; var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); -var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); +var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -83,7 +83,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -135,7 +135,7 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -150,15 +150,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok @@ -192,7 +192,7 @@ var s3; var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); -var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); +var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error var r4; var sIPromise; var sPromise; @@ -249,7 +249,7 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(function (x) { return x; }); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok @@ -263,14 +263,14 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(function (x) { return x; }); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok var s12 = testFunction12(function (x) { return x; }); diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index 6c127f85f03..e512ca73277 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -46,7 +46,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -127,7 +127,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. - var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); + var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -205,7 +205,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok - var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + var r9d = r9.then(testFunction, sIPromise, nIPromise); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok @@ -221,7 +221,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok - var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + var s9f = s9.then(testFunction, sIPromise, nIPromise); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok @@ -230,7 +230,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok - var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + var r10d = r10.then(testFunction, sIPromise, nIPromise); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok @@ -240,13 +240,13 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; - var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok + var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. var s11: Promise; diff --git a/tests/baselines/reference/promisePermutations2.js b/tests/baselines/reference/promisePermutations2.js index 008594ee120..a7b5d8cf835 100644 --- a/tests/baselines/reference/promisePermutations2.js +++ b/tests/baselines/reference/promisePermutations2.js @@ -11,7 +11,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -82,7 +82,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -126,7 +126,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -134,14 +134,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -149,11 +149,11 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok @@ -241,7 +241,7 @@ var r9; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -249,13 +249,13 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(function (x) { return x; }); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(function (x) { return x; }); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -263,10 +263,10 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index 636e89645b6..97d47cc7f7f 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -48,7 +48,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of interface IPromise { then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -131,7 +131,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: number, y?: string) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. - var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); + var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -209,7 +209,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok - var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok + var r9d = r9.then(testFunction, sIPromise, nIPromise); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok @@ -225,7 +225,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok - var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok + var s9f = s9.then(testFunction, sIPromise, nIPromise); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok @@ -234,7 +234,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok - var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok + var r10d = r10.then(testFunction, sIPromise, nIPromise); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok @@ -244,7 +244,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok - var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok + var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok @@ -257,10 +257,10 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. - var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok + var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => Promise'. - var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok + var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: number): Promise; (x: string): Promise; }' is not assignable to parameter of type '(value: number) => IPromise'. diff --git a/tests/baselines/reference/promisePermutations3.js b/tests/baselines/reference/promisePermutations3.js index d65d8c233f8..eb9c882b971 100644 --- a/tests/baselines/reference/promisePermutations3.js +++ b/tests/baselines/reference/promisePermutations3.js @@ -11,7 +11,7 @@ interface Promise { interface IPromise { then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -82,7 +82,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -126,7 +126,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -134,14 +134,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -149,15 +149,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok @@ -241,7 +241,7 @@ var r9; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -249,13 +249,13 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(function (x) { return x; }); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(function (x) { return x; }); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -263,14 +263,14 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok var s11; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(function (x) { return x; }); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok var s12 = testFunction12(function (x) { return x; }); diff --git a/tests/baselines/reference/returnTypeParameterWithModules.types b/tests/baselines/reference/returnTypeParameterWithModules.types index adcc1b4bcee..4be0efcd2a5 100644 --- a/tests/baselines/reference/returnTypeParameterWithModules.types +++ b/tests/baselines/reference/returnTypeParameterWithModules.types @@ -21,7 +21,7 @@ module M1 { >reduce : { (callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue?: any): any; (callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U; } >apply : (thisArg: any, argArray?: any) => any >ar : any ->e ? [f, e] : [f] : any +>e ? [f, e] : [f] : any[] >e : any >[f, e] : any[] >f : any diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt index 7f23cb39c8c..1a2ced3b6f2 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.errors.txt @@ -1,13 +1,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(3,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(9,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(9,26): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(18,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'r2' must be of type 'U | V', but here has type 'T | V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(19,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'r2' must be of type 'U | V', but here has type 'T | V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(23,13): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts(143,18): error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts (7 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts (5 errors) ==== // checking whether other types are subtypes of type parameters with constraints function f1(x: T, y: U) { @@ -31,12 +29,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf var r2 = true ? y : z; // ok - var r2 = true ? z : x; - ~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r2' must be of type 'U | V', but here has type 'T | V'. - var r2 = true ? x : z; - ~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r2' must be of type 'U | V', but here has type 'T | V'. + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T @@ -79,18 +73,18 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf } function f5(x: T) { - var r1 = true ? 1 : x; // error - var r1 = true ? x : 1; // error + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x: T) { - var r2 = true ? '' : x; // error - var r2 = true ? x : ''; // error + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x: T) { - var r3 = true ? true : x; // error - var r3 = true ? x : true; // error + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x: T) { @@ -137,11 +131,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf } function f16(x: T) { - var r13 = true ? E : x; // BUG 831833 - var r13 = true ? x : E; // BUG 831833 + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok - var r14 = true ? E.A : x; // BUG 831833 - var r14 = true ? x : E.A; // BUG 831833 + var r14 = true ? E.A : x; // ok + var r14 = true ? x : E.A; // ok } function f17(x: T) { diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js index bf582fe13e5..bd729f36222 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js @@ -16,8 +16,8 @@ function f2(x: T, y: U, z: V) { var r2 = true ? y : z; // ok - var r2 = true ? z : x; - var r2 = true ? x : z; + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T @@ -58,18 +58,18 @@ function f4(x: T) { } function f5(x: T) { - var r1 = true ? 1 : x; // error - var r1 = true ? x : 1; // error + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x: T) { - var r2 = true ? '' : x; // error - var r2 = true ? x : ''; // error + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x: T) { - var r3 = true ? true : x; // error - var r3 = true ? x : true; // error + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x: T) { @@ -116,11 +116,11 @@ function f15>(x: T) { } function f16(x: T) { - var r13 = true ? E : x; // BUG 831833 - var r13 = true ? x : E; // BUG 831833 + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok - var r14 = true ? E.A : x; // BUG 831833 - var r14 = true ? x : E.A; // BUG 831833 + var r14 = true ? E.A : x; // ok + var r14 = true ? x : E.A; // ok } function f17(x: T) { @@ -171,8 +171,8 @@ function f2(x, y, z) { var r2 = true ? z : y; var r2 = true ? y : z; // ok - var r2 = true ? z : x; - var r2 = true ? x : z; + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T function f3(x, y) { @@ -222,16 +222,16 @@ function f4(x) { var r0b = true ? x : u; // ok } function f5(x) { - var r1 = true ? 1 : x; // error - var r1 = true ? x : 1; // error + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x) { - var r2 = true ? '' : x; // error - var r2 = true ? x : ''; // error + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x) { - var r3 = true ? true : x; // error - var r3 = true ? x : true; // error + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x) { var r4 = true ? new Date() : x; // ok @@ -275,10 +275,10 @@ function f15(x) { var r12 = true ? x : c2; // ok } function f16(x) { - var r13 = true ? E : x; // BUG 831833 - var r13 = true ? x : E; // BUG 831833 - var r14 = true ? 0 /* A */ : x; // BUG 831833 - var r14 = true ? x : 0 /* A */; // BUG 831833 + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok + var r14 = true ? 0 /* A */ : x; // ok + var r14 = true ? x : 0 /* A */; // ok } function f17(x) { var af; diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt index edb09275bed..2a5fa5ad362 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.errors.txt @@ -11,11 +11,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; } \ No newline at end of file diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js index 229beffd334..790c0fa5b96 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.js @@ -6,11 +6,11 @@ function f(t: T, u: U, v: V) { var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; } @@ -21,10 +21,10 @@ function f(t, u, v) { // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt index 480090391e2..872cb8ef965 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -26,15 +26,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf class Foo { foo: number; } function f(t: T, u: U, v: V) { - // error + // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; @@ -46,7 +46,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js index 96983ecf68f..f1cf61d484f 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.js @@ -3,15 +3,15 @@ class Foo { foo: number; } function f(t: T, u: U, v: V) { - // error + // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; @@ -23,7 +23,7 @@ function f(t: T, u: U, v: V) { var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; @@ -92,13 +92,13 @@ var Foo = (function () { return Foo; })(); function f(t, u, v) { - // error + // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; // ok @@ -107,7 +107,7 @@ function f(t, u, v) { // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt index 4f11fc6e1b9..f4b1d7ef041 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -98,53 +98,53 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. ~~~~~~~~~~~~~~~~ !!! error TS2313: Constraint of a type parameter cannot reference any type parameter from the same type parameter list. - // error + // ok var r1 = true ? t : u; var r1 = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; - // ok? + // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; - // ok? + // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // ok? + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; - // ok? + // ok var r7 = true ? t : new Foo(); var r7 = true ? new Foo() : t; - // ok? + // ok var r8 = true ? u : new Foo(); var r8 = true ? new Foo() : u; - // ok? + // ok var r9 = true ? v : new Foo(); var r9 = true ? new Foo() : v; - // ok? + // ok var r10 = true ? t : new Foo(); var r10 = true ? new Foo() : t; - // ok? + // ok var r11 = true ? u : new Foo(); var r11 = true ? new Foo() : u; - // ok? + // ok var r12 = true ? v : new Foo(); var r12 = true ? new Foo() : v; } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js index e345d746bf7..1caa7d99087 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.js @@ -3,53 +3,53 @@ class Foo { foo: T; } function f, U extends Foo, V extends Foo>(t: T, u: U, v: V) { - // error + // ok var r1 = true ? t : u; var r1 = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; - // ok? + // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; - // ok? + // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // ok? + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; - // ok? + // ok var r7 = true ? t : new Foo(); var r7 = true ? new Foo() : t; - // ok? + // ok var r8 = true ? u : new Foo(); var r8 = true ? new Foo() : u; - // ok? + // ok var r9 = true ? v : new Foo(); var r9 = true ? new Foo() : v; - // ok? + // ok var r10 = true ? t : new Foo(); var r10 = true ? new Foo() : t; - // ok? + // ok var r11 = true ? u : new Foo(); var r11 = true ? new Foo() : u; - // ok? + // ok var r12 = true ? v : new Foo(); var r12 = true ? new Foo() : v; } @@ -171,40 +171,40 @@ var Foo = (function () { return Foo; })(); function f(t, u, v) { - // error + // ok var r1 = true ? t : u; var r1 = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; - // ok? + // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; - // ok? + // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // ok? + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; - // ok? + // ok var r7 = true ? t : new Foo(); var r7 = true ? new Foo() : t; - // ok? + // ok var r8 = true ? u : new Foo(); var r8 = true ? new Foo() : u; - // ok? + // ok var r9 = true ? v : new Foo(); var r9 = true ? new Foo() : v; - // ok? + // ok var r10 = true ? t : new Foo(); var r10 = true ? new Foo() : t; - // ok? + // ok var r11 = true ? u : new Foo(); var r11 = true ? new Foo() : u; - // ok? + // ok var r12 = true ? v : new Foo(); var r12 = true ? new Foo() : v; } diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt index b3eae74f568..ac17303572d 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt @@ -48,4 +48,4 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW // object literal case var a: { Foo: Base; } var b: { Foo?: Derived; } - var r = true ? a : b; // error \ No newline at end of file + var r = true ? a : b; // ok \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js index 186f3ba4544..33c4cc927da 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.js @@ -31,11 +31,11 @@ interface S3 extends T3 { // object literal case var a: { Foo: Base; } var b: { Foo?: Derived; } -var r = true ? a : b; // error +var r = true ? a : b; // ok //// [subtypingWithObjectMembersOptionality2.js] // Derived member is optional but base member is not, should be an error // object literal case var a; var b; -var r = true ? a : b; // error +var r = true ? a : b; // ok diff --git a/tests/baselines/reference/tupleTypes.errors.txt b/tests/baselines/reference/tupleTypes.errors.txt index 2ce9b044f48..824148bc2e2 100644 --- a/tests/baselines/reference/tupleTypes.errors.txt +++ b/tests/baselines/reference/tupleTypes.errors.txt @@ -1,5 +1,4 @@ tests/cases/compiler/tupleTypes.ts(1,9): error TS1122: A tuple type element list cannot be empty. -tests/cases/compiler/tupleTypes.ts(12,5): error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type 'string | number', but here has type '{}'. tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type 'Array' is not assignable to type '[number, string]': Property '0' is missing in type 'Array'. tests/cases/compiler/tupleTypes.ts(15,1): error TS2322: Type '[number]' is not assignable to type '[number, string]': @@ -7,7 +6,6 @@ tests/cases/compiler/tupleTypes.ts(15,1): error TS2322: Type '[number]' is not a tests/cases/compiler/tupleTypes.ts(17,1): error TS2322: Type '[string, number]' is not assignable to type '[number, string]': Types of property '0' are incompatible: Type 'string' is not assignable to type 'number'. -tests/cases/compiler/tupleTypes.ts(36,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'tt2' must be of type 'string | number', but here has type '{}'. tests/cases/compiler/tupleTypes.ts(41,1): error TS2323: Type 'Array' is not assignable to type '[number, string]'. tests/cases/compiler/tupleTypes.ts(47,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]': Types of property 'pop' are incompatible: @@ -26,7 +24,7 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n Type '{}' is not assignable to type 'string'. -==== tests/cases/compiler/tupleTypes.ts (11 errors) ==== +==== tests/cases/compiler/tupleTypes.ts (9 errors) ==== var v1: []; // Error ~~ !!! error TS1122: A tuple type element list cannot be empty. @@ -39,10 +37,8 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n var t0: number; var t1 = t[1]; // string var t1: string; - var t2 = t[2]; // {} - var t2: {}; - ~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type 'string | number', but here has type '{}'. + var t2 = t[2]; // number|string + var t2: number|string; t = []; // Error ~ @@ -75,10 +71,8 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n var tt0: number; var tt1 = tt[1]; var tt1: string; - var tt2 = tt[2]; - var tt2: {}; - ~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'tt2' must be of type 'string | number', but here has type '{}'. + var tt2 = tt[2]; + var tt2: number | string; tt = tuple2(1, undefined); tt = [1, undefined]; diff --git a/tests/baselines/reference/typeArgInference2.errors.txt b/tests/baselines/reference/typeArgInference2.errors.txt index 3e148ca1da6..cf188972b7d 100644 --- a/tests/baselines/reference/typeArgInference2.errors.txt +++ b/tests/baselines/reference/typeArgInference2.errors.txt @@ -13,6 +13,6 @@ tests/cases/compiler/typeArgInference2.ts(12,10): error TS2346: Supplied paramet var z3 = foo({ name: null }); // { name: any } var z4 = foo({ name: "abc" }); // { name: string } var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } - var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item + var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgInference2.js b/tests/baselines/reference/typeArgInference2.js index ef76c9b33e7..193345cdeb3 100644 --- a/tests/baselines/reference/typeArgInference2.js +++ b/tests/baselines/reference/typeArgInference2.js @@ -10,7 +10,7 @@ var z2 = foo(); // Item var z3 = foo({ name: null }); // { name: any } var z4 = foo({ name: "abc" }); // { name: string } var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item +var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error //// [typeArgInference2.js] var z1 = foo(null); // any @@ -18,4 +18,4 @@ var z2 = foo(); // Item var z3 = foo({ name: null }); // { name: any } var z4 = foo({ name: "abc" }); // { name: string } var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item +var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index a23eff1f8ea..c73c63aee26 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -309,7 +309,7 @@ _.countBy([1, 2, 3, 4, 5], (num) => num % 2 == 0 ? 'even' : 'odd'); >[1, 2, 3, 4, 5] : number[] >(num) => num % 2 == 0 ? 'even' : 'odd' : (num: number) => string >num : number ->num % 2 == 0 ? 'even' : 'odd' : any +>num % 2 == 0 ? 'even' : 'odd' : string >num % 2 == 0 : boolean >num % 2 : number >num : number diff --git a/tests/cases/compiler/arrayBestCommonTypes.ts b/tests/cases/compiler/arrayBestCommonTypes.ts index ee09c4d07f6..c7466b5181e 100644 --- a/tests/cases/compiler/arrayBestCommonTypes.ts +++ b/tests/cases/compiler/arrayBestCommonTypes.ts @@ -1,52 +1,106 @@ -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() { - (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])); + 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; } - (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])); + public x() { + (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([[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() } ]; + (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])); - 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(); + (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() { + (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: 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]; + } + } +} diff --git a/tests/cases/compiler/arrayLiteralContextualType.ts b/tests/cases/compiler/arrayLiteralContextualType.ts index 1518d2e4ac0..be05929e8e7 100644 --- a/tests/cases/compiler/arrayLiteralContextualType.ts +++ b/tests/cases/compiler/arrayLiteralContextualType.ts @@ -25,5 +25,5 @@ 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 \ No newline at end of file +foo(arr); // ok because arr is Array not {}[] +bar(arr); // ok because arr is Array not {}[] \ No newline at end of file diff --git a/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts b/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts index bd1f22f44dc..1ea001057a9 100644 --- a/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts +++ b/tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts @@ -1,3 +1,3 @@ var f10: (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 \ No newline at end of file +f10('', () => a => a.foo, ''); // a is string +var r9 = f10('', () => (a => a.foo), 1); // error \ No newline at end of file diff --git a/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts b/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts index b9fecdc6ffc..254197bf309 100644 --- a/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts +++ b/tests/cases/compiler/defaultBestCommonTypesHaveDecls.ts @@ -1,18 +1,14 @@ - var obj1: {}; - obj1.length; - - var obj2: Object; - obj2.length; - - function concat(x: T, y: T): T { return null; } +var result = concat(1, ""); // error +var elementCount = result.length; -var result = concat(1, ""); +function concat2(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 diff --git a/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts b/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts index f77ad5105ab..cadd60ea398 100644 --- a/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts +++ b/tests/cases/compiler/nonContextuallyTypedLogicalOr.ts @@ -11,6 +11,4 @@ interface Ellement { var c: Contextual; var e: Ellement; -// This should error. Even though we are contextually typing e with Contextual, the RHS still -// needs to be a supertype of the LHS to win as the best common type. (c || e).dummy; \ No newline at end of file diff --git a/tests/cases/compiler/promisePermutations.ts b/tests/cases/compiler/promisePermutations.ts index c5091aaa630..0ce62be8181 100644 --- a/tests/cases/compiler/promisePermutations.ts +++ b/tests/cases/compiler/promisePermutations.ts @@ -11,7 +11,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -71,7 +71,7 @@ var s3: Promise; var s3a = s3.then(testFunction3, testFunction3, testFunction3); var s3b = s3.then(testFunction3P, testFunction3P, testFunction3P); var s3c = s3.then(testFunction3P, testFunction3, testFunction3); -var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); +var s3d = s3.then(testFunction3P, testFunction3, testFunction3).then(testFunction3, testFunction3, testFunction3); // error var r4: IPromise; var sIPromise: (x: any) => IPromise; @@ -82,7 +82,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -134,7 +134,7 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); @@ -149,15 +149,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/cases/compiler/promisePermutations2.ts b/tests/cases/compiler/promisePermutations2.ts index 66f9806de00..05a60860929 100644 --- a/tests/cases/compiler/promisePermutations2.ts +++ b/tests/cases/compiler/promisePermutations2.ts @@ -10,7 +10,7 @@ interface IPromise { then(success?: (value: T) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -81,7 +81,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -125,7 +125,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -133,14 +133,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -148,11 +148,11 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; -var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok +var r11a = r11.then(testFunction11, testFunction11, testFunction11); // error var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok diff --git a/tests/cases/compiler/promisePermutations3.ts b/tests/cases/compiler/promisePermutations3.ts index 78d6b17c9ec..3aab00b0ed0 100644 --- a/tests/cases/compiler/promisePermutations3.ts +++ b/tests/cases/compiler/promisePermutations3.ts @@ -10,7 +10,7 @@ interface Promise { interface IPromise { then(success?: (value: T) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; - done?(success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; + done? (success?: (value: T) => any, error?: (error: any) => any, progress?: (progress: any) => void): void; } declare function testFunction(): IPromise; @@ -81,7 +81,7 @@ var s4: Promise; var s4a = s4.then(testFunction4, testFunction4, testFunction4); // error var s4b = s4.then(testFunction4P, testFunction4P, testFunction4P); // error var s4c = s4.then(testFunction4P, testFunction4, testFunction4); // error -var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); +var s4d = s4.then(sIPromise, testFunction4P, testFunction4).then(sIPromise, testFunction4P, testFunction4); var r5: IPromise; var r5a = r5.then(testFunction5, testFunction5, testFunction5); // error @@ -125,7 +125,7 @@ var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok -var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok +var r9d = r9.then(testFunction, sIPromise, nIPromise); // error var r9e = r9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error @@ -133,14 +133,14 @@ var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error var s9d = s9.then(sPromise, sPromise, sPromise); // ok var s9e = s9.then(nPromise, nPromise, nPromise); // ok -var s9f = s9.then(testFunction, sIPromise, nIPromise); // ok +var s9f = s9.then(testFunction, sIPromise, nIPromise); // error var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var r10 = testFunction10(x => x); var r10a = r10.then(testFunction10, testFunction10, testFunction10); // ok var r10b = r10.then(sIPromise, sIPromise, sIPromise); // ok var r10c = r10.then(nIPromise, nIPromise, nIPromise); // ok -var r10d = r10.then(testFunction, sIPromise, nIPromise); // ok +var r10d = r10.then(testFunction, sIPromise, nIPromise); // error var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok var s10 = testFunction10P(x => x); var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok @@ -148,15 +148,15 @@ var s10b = s10.then(testFunction10P, testFunction10P, testFunction10P); // ok var s10c = s10.then(testFunction10P, testFunction10, testFunction10); // ok var s10d = s10.then(sPromise, sPromise, sPromise); // ok var s10e = s10.then(nIPromise, nPromise, nIPromise); // ok -var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // ok +var s10f = s10.then(testFunctionP, sIPromise, nIPromise); // error var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; var r11a = r11.then(testFunction11, testFunction11, testFunction11); // ok var s11: Promise; var s11a = s11.then(testFunction11, testFunction11, testFunction11); // ok -var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok -var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // ok +var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error +var s11c = s11.then(testFunction11P, testFunction11, testFunction11); // error var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/cases/compiler/tupleTypes.ts b/tests/cases/compiler/tupleTypes.ts index 3b22c284cb1..80181f8b332 100644 --- a/tests/cases/compiler/tupleTypes.ts +++ b/tests/cases/compiler/tupleTypes.ts @@ -8,8 +8,8 @@ var t0 = t[0]; // number var t0: number; var t1 = t[1]; // string var t1: string; -var t2 = t[2]; // {} -var t2: {}; +var t2 = t[2]; // number|string +var t2: number|string; t = []; // Error t = [1]; // Error @@ -32,8 +32,8 @@ var tt0 = tt[0]; var tt0: number; var tt1 = tt[1]; var tt1: string; -var tt2 = tt[2]; -var tt2: {}; +var tt2 = tt[2]; +var tt2: number | string; tt = tuple2(1, undefined); tt = [1, undefined]; diff --git a/tests/cases/compiler/typeArgInference2.ts b/tests/cases/compiler/typeArgInference2.ts index 523d1eab506..5bf8599996e 100644 --- a/tests/cases/compiler/typeArgInference2.ts +++ b/tests/cases/compiler/typeArgInference2.ts @@ -1,12 +1,12 @@ -interface Item { - name: string; -} - -declare function foo(x?: T, y?: T): T; - -var z1 = foo(null); // any -var z2 = foo(); // Item -var z3 = foo({ name: null }); // { name: any } -var z4 = foo({ name: "abc" }); // { name: string } -var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } -var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // Item \ No newline at end of file +interface Item { + name: string; +} + +declare function foo(x?: T, y?: T): T; + +var z1 = foo(null); // any +var z2 = foo(); // Item +var z3 = foo({ name: null }); // { name: any } +var z4 = foo({ name: "abc" }); // { name: string } +var z5 = foo({ name: "abc", a: 5 }); // { name: string; a: number } +var z6 = foo({ name: "abc", a: 5 }, { name: "def", b: 5 }); // error \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts index b4b85573755..41c5a0b8100 100644 --- a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts @@ -1,28 +1,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; // Should OK, not be a parse error @@ -30,7 +23,6 @@ var classTypeArray: Array; // 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; } diff --git a/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts b/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts index 34ef4b3ca8c..feaa3c5a280 100644 --- a/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts +++ b/tests/cases/conformance/expressions/conditonalOperator/conditionalOperatorWithoutIdenticalBCT.ts @@ -1,21 +1,20 @@ -//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 }; -class B extends X { propertyB: string }; - -var x: X; -var a: A; -var b: B; - -//Expect to have compiler errors -//Be not contextually typed -true ? a : b; -var result1 = true ? a : b; - -//Be contextually typed and and bct is not identical -var result2: A = true ? a : b; -var result3: B = true ? a : b; - -var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2; -var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2; +//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 }; +class B extends X { propertyB: string }; + +var x: X; +var a: A; +var b: B; + +// No errors anymore, uses union types +true ? a : b; +var result1 = true ? a : b; + +//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; + +var result4: (t: X) => number = true ? (m) => m.propertyX1 : (n) => n.propertyX2; +var result5: (t: X) => string = true ? (m) => m.propertyX1 : (n) => n.propertyX2; var result6: (t: X) => boolean = true ? (m) => m.propertyX1 : (n) => n.propertyX2; \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts index 68ac4cff026..9edf4f5f417 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts @@ -15,8 +15,8 @@ function f2(x: T, y: U, z: V) { var r2 = true ? y : z; // ok - var r2 = true ? z : x; - var r2 = true ? x : z; + var r2a = true ? z : x; + var r2b = true ? x : z; } // Date > U > T @@ -57,18 +57,18 @@ function f4(x: T) { } function f5(x: T) { - var r1 = true ? 1 : x; // error - var r1 = true ? x : 1; // error + var r1 = true ? 1 : x; // ok + var r1 = true ? x : 1; // ok } function f6(x: T) { - var r2 = true ? '' : x; // error - var r2 = true ? x : ''; // error + var r2 = true ? '' : x; // ok + var r2 = true ? x : ''; // ok } function f7(x: T) { - var r3 = true ? true : x; // error - var r3 = true ? x : true; // error + var r3 = true ? true : x; // ok + var r3 = true ? x : true; // ok } function f8(x: T) { @@ -115,11 +115,11 @@ function f15>(x: T) { } function f16(x: T) { - var r13 = true ? E : x; // BUG 831833 - var r13 = true ? x : E; // BUG 831833 + var r13 = true ? E : x; // ok + var r13 = true ? x : E; // ok - var r14 = true ? E.A : x; // BUG 831833 - var r14 = true ? x : E.A; // BUG 831833 + var r14 = true ? E.A : x; // ok + var r14 = true ? x : E.A; // ok } function f17(x: T) { diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts index 10021cdcc06..96218dce43e 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints3.ts @@ -5,11 +5,11 @@ function f(t: T, u: U, v: V) { var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; } \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts index a4e691edbb4..0dc53908ea3 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts @@ -2,15 +2,15 @@ class Foo { foo: number; } function f(t: T, u: U, v: V) { - // error + // ok var r = true ? t : u; var r = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; @@ -22,7 +22,7 @@ function f(t: T, u: U, v: V) { var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // BUG, should be error + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts index dc3f2917ec1..f63b63432e5 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts @@ -2,53 +2,53 @@ class Foo { foo: T; } function f, U extends Foo, V extends Foo>(t: T, u: U, v: V) { - // error + // ok var r1 = true ? t : u; var r1 = true ? u : t; - // error + // ok var r2 = true ? t : v; var r2 = true ? v : t; - // error + // ok var r3 = true ? v : u; var r3 = true ? u : v; - // ok? + // ok var r4 = true ? t : new Foo(); var r4 = true ? new Foo() : t; - // ok? + // ok var r5 = true ? u : new Foo(); var r5 = true ? new Foo() : u; - // ok? + // ok var r6 = true ? v : new Foo(); var r6 = true ? new Foo() : v; - // ok? + // ok var r7 = true ? t : new Foo(); var r7 = true ? new Foo() : t; - // ok? + // ok var r8 = true ? u : new Foo(); var r8 = true ? new Foo() : u; - // ok? + // ok var r9 = true ? v : new Foo(); var r9 = true ? new Foo() : v; - // ok? + // ok var r10 = true ? t : new Foo(); var r10 = true ? new Foo() : t; - // ok? + // ok var r11 = true ? u : new Foo(); var r11 = true ? new Foo() : u; - // ok? + // ok var r12 = true ? v : new Foo(); var r12 = true ? new Foo() : v; } diff --git a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts index 601d85704eb..ac8f5642f70 100644 --- a/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts +++ b/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembersOptionality2.ts @@ -30,4 +30,4 @@ interface S3 extends T3 { // object literal case var a: { Foo: Base; } var b: { Foo?: Derived; } -var r = true ? a : b; // error \ No newline at end of file +var r = true ? a : b; // ok \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts index 3f2e17c6b05..97359cde959 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments.ts @@ -23,14 +23,14 @@ function foo3(x: T, cb: (a: T) => U, y: U) { var r7 = foo3(1, (a: Z) => '', ''); // string -var r8 = foo3(1, function (a) { return '' }, 1); // {} +var r8 = foo3(1, function (a) { return '' }, 1); // error var r9 = foo3(1, (a) => '', ''); // string function other(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 } \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts index f313d638bfb..0d02afe9c88 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments2.ts @@ -26,7 +26,7 @@ function foo2(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('', i2); // string @@ -37,5 +37,5 @@ function foo3(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('', i2, ''); // string \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts index 54a7cf7ebc6..c37b2e31333 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments2.ts @@ -1,36 +1,73 @@ // 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: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; +module onlyT { + function foo(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(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(a: (x: T) => T, b: (x: T) => T) { + var r: (x: T) => T; + return r; + } + + function other3(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(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(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -function other2(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(a: (x: T) => T, b: (x: T) => T) { - var r: (x: T) => T; - return r; -} + function other2(x: T) { + var r7 = foo((a: T) => a, (b: T) => b); + var r9 = r7(new Date()); + var r10 = r7(1); + } -function other3(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(a: (x: T) => T, b: (x: U) => U) { + var r: (x: T) => T; + return r; + } -enum E { A } -enum F { A } + function other3(x: T) { + var r7 = foo2((a: T) => a, (b: T) => b); + var r7b = foo2((a) => a, (b) => b); + } -function foo3(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 \ No newline at end of file + function foo3(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); +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts index 65f22a3fd3f..82b917efa3e 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts @@ -29,5 +29,5 @@ 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) => {} \ No newline at end of file +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 \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts index 1e5976b33e5..75b0462b689 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectLiteralArgs.ts @@ -2,7 +2,7 @@ function foo(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({ bar: 1, baz: '' }); // T = Object \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts index 8bb5d234bb5..527286e6ee2 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithOverloadedConstructorTypedArguments.ts @@ -33,7 +33,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(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }) { diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts index a3b02eaf4e4..f429cd5169d 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericClassWithFunctionTypedMemberArguments.ts @@ -54,11 +54,11 @@ module WithCandidates { var c3: C3; function other(t: T, u: U) { - var r10 = c.foo2(1, (x: T) => ''); // string, non-generic signature allows inferences to be made + var r10 = c.foo2(1, (x: T) => ''); // error var r10 = c.foo2(1, (x) => ''); // string - var r11 = c3.foo3(1, (x: T) => '', ''); // string - var r11b = c3.foo3(1, (x: T) => '', 1); // {} - var r12 = c3.foo3(1, function (a) { return '' }, 1); // {} + var r11 = c3.foo3(1, (x: T) => '', ''); // error + var r11b = c3.foo3(1, (x: T) => '', 1); // error + var r12 = c3.foo3(1, function (a) { return '' }, 1); // error } } \ No newline at end of file