Merge pull request #11263 from Microsoft/controlFlowLetVar

Control flow analysis for implicit any variables
This commit is contained in:
Anders Hejlsberg
2016-10-06 14:23:38 -07:00
committed by GitHub
115 changed files with 2072 additions and 431 deletions

View File

@@ -120,6 +120,7 @@ namespace ts {
const resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__");
const anyType = createIntrinsicType(TypeFlags.Any, "any");
const autoType = createIntrinsicType(TypeFlags.Any, "any");
const unknownType = createIntrinsicType(TypeFlags.Any, "unknown");
const undefinedType = createIntrinsicType(TypeFlags.Undefined, "undefined");
const undefinedWideningType = strictNullChecks ? undefinedType : createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsWideningType, "undefined");
@@ -3056,6 +3057,11 @@ namespace ts {
return undefined;
}
function isAutoVariableInitializer(initializer: Expression) {
const expr = initializer && skipParentheses(initializer);
return !expr || expr.kind === SyntaxKind.NullKeyword || expr.kind === SyntaxKind.Identifier && getResolvedSymbol(<Identifier>expr) === undefinedSymbol;
}
function addOptionality(type: Type, optional: boolean): Type {
return strictNullChecks && optional ? includeFalsyTypes(type, TypeFlags.Undefined) : type;
}
@@ -3094,6 +3100,14 @@ namespace ts {
return addOptionality(getTypeFromTypeNode(declaration.type), /*optional*/ declaration.questionToken && includeOptionality);
}
// Use control flow type inference for non-ambient, non-exported var or let variables with no initializer
// or a 'null' or 'undefined' initializer.
if (declaration.kind === SyntaxKind.VariableDeclaration && !isBindingPattern(declaration.name) &&
!(getCombinedNodeFlags(declaration) & NodeFlags.Const) && !(getCombinedModifierFlags(declaration) & ModifierFlags.Export) &&
!isInAmbientContext(declaration) && isAutoVariableInitializer(declaration.initializer)) {
return autoType;
}
if (declaration.kind === SyntaxKind.Parameter) {
const func = <FunctionLikeDeclaration>declaration.parent;
// For a parameter of a set accessor, use the type of the get accessor if one is present
@@ -8460,7 +8474,9 @@ namespace ts {
if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) {
return declaredType;
}
const initialType = assumeInitialized ? declaredType : includeFalsyTypes(declaredType, TypeFlags.Undefined);
const initialType = assumeInitialized ? declaredType :
declaredType === autoType ? undefinedType :
includeFalsyTypes(declaredType, TypeFlags.Undefined);
const visitedFlowStart = visitedFlowCount;
const result = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode));
visitedFlowCount = visitedFlowStart;
@@ -8534,9 +8550,12 @@ namespace ts {
// Assignments only narrow the computed type if the declared type is a union type. Thus, we
// only need to evaluate the assigned type if the declared type is a union type.
if (isMatchingReference(reference, node)) {
const isIncrementOrDecrement = node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression;
return declaredType.flags & TypeFlags.Union && !isIncrementOrDecrement ?
getAssignmentReducedType(<UnionType>declaredType, getInitialOrAssignedType(node)) :
if (node.parent.kind === SyntaxKind.PrefixUnaryExpression || node.parent.kind === SyntaxKind.PostfixUnaryExpression) {
const flowType = getTypeAtFlowNode(flow.antecedent);
return createFlowType(getBaseTypeOfLiteralType(getTypeFromFlowType(flowType)), isIncomplete(flowType));
}
return declaredType === autoType ? getBaseTypeOfLiteralType(getInitialOrAssignedType(node)) :
declaredType.flags & TypeFlags.Union ? getAssignmentReducedType(<UnionType>declaredType, getInitialOrAssignedType(node)) :
declaredType;
}
// We didn't have a direct match. However, if the reference is a dotted name, this
@@ -8980,7 +8999,7 @@ namespace ts {
if (isRightSideOfQualifiedNameOrPropertyAccess(location)) {
location = location.parent;
}
if (isExpression(location) && !isAssignmentTarget(location)) {
if (isPartOfExpression(location) && !isAssignmentTarget(location)) {
const type = checkExpression(<Expression>location);
if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) {
return type;
@@ -9151,13 +9170,23 @@ namespace ts {
// We only look for uninitialized variables in strict null checking mode, and only when we can analyze
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
// declaration container are the same).
const assumeInitialized = !strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isParameter ||
isOuterVariable || isInAmbientContext(declaration);
const assumeInitialized = isParameter || isOuterVariable ||
type !== autoType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0) ||
isInAmbientContext(declaration);
const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer);
// A variable is considered uninitialized when it is possible to analyze the entire control flow graph
// from declaration to use, and when the variable's declared type doesn't include undefined but the
// control flow based type does include undefined.
if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) {
if (type === autoType) {
if (flowType === autoType) {
if (compilerOptions.noImplicitAny) {
error(declaration.name, Diagnostics.Variable_0_implicitly_has_type_any_in_some_locations_where_its_type_cannot_be_determined, symbolToString(symbol));
error(node, Diagnostics.Variable_0_implicitly_has_an_1_type, symbolToString(symbol), typeToString(anyType));
}
return anyType;
}
}
else if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) {
error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol));
// Return the declared type to reduce follow-on errors
return type;
@@ -15906,6 +15935,10 @@ namespace ts {
}
}
function convertAutoToAny(type: Type) {
return type === autoType ? anyType : type;
}
// Check variable, parameter, or property declaration
function checkVariableLikeDeclaration(node: VariableLikeDeclaration) {
checkDecorators(node);
@@ -15956,7 +15989,7 @@ namespace ts {
return;
}
const symbol = getSymbolOfNode(node);
const type = getTypeOfVariableOrParameterOrProperty(symbol);
const type = convertAutoToAny(getTypeOfVariableOrParameterOrProperty(symbol));
if (node === symbol.valueDeclaration) {
// Node is the primary declaration of the symbol, just validate the initializer
// Don't validate for-in initializer as it is already an error
@@ -15968,7 +16001,7 @@ namespace ts {
else {
// Node is a secondary declaration, check that type is identical to primary declaration and check that
// initializer is consistent with type associated with the node
const declarationType = getWidenedTypeForVariableLikeDeclaration(node);
const declarationType = convertAutoToAny(getWidenedTypeForVariableLikeDeclaration(node));
if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) {
error(node.name, Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, declarationNameToString(node.name), typeToString(type), typeToString(declarationType));
}

View File

@@ -2957,6 +2957,10 @@
"category": "Error",
"code": 7033
},
"Variable '{0}' implicitly has type 'any' in some locations where its type cannot be determined.": {
"category": "Error",
"code": 7034
},
"You cannot rename this element.": {
"category": "Error",
"code": 8000

View File

@@ -4,7 +4,7 @@ tests/cases/conformance/Symbols/ES5SymbolProperty2.ts(10,11): error TS2304: Cann
==== tests/cases/conformance/Symbols/ES5SymbolProperty2.ts (2 errors) ====
module M {
var Symbol;
var Symbol: any;
export class C {
[Symbol.iterator]() { }

View File

@@ -1,6 +1,6 @@
//// [ES5SymbolProperty2.ts]
module M {
var Symbol;
var Symbol: any;
export class C {
[Symbol.iterator]() { }

View File

@@ -2,7 +2,7 @@ tests/cases/conformance/Symbols/ES5SymbolProperty3.ts(4,6): error TS2471: A comp
==== tests/cases/conformance/Symbols/ES5SymbolProperty3.ts (1 errors) ====
var Symbol;
var Symbol: any;
class C {
[Symbol.iterator]() { }

View File

@@ -1,5 +1,5 @@
//// [ES5SymbolProperty3.ts]
var Symbol;
var Symbol: any;
class C {
[Symbol.iterator]() { }

View File

@@ -1,5 +1,5 @@
//// [anyPlusAny1.ts]
var x;
var x: any;
x.name = "hello";
var z = x + x;

View File

@@ -1,5 +1,5 @@
=== tests/cases/compiler/anyPlusAny1.ts ===
var x;
var x: any;
>x : Symbol(x, Decl(anyPlusAny1.ts, 0, 3))
x.name = "hello";

View File

@@ -1,5 +1,5 @@
=== tests/cases/compiler/anyPlusAny1.ts ===
var x;
var x: any;
>x : any
x.name = "hello";

View File

@@ -10,10 +10,10 @@ var Foo;
>Foo : any
type
>type : any
>type : undefined
Foo = string;
>Foo = string : any
>Foo = string : undefined
>Foo : any
>string : any
>string : undefined

View File

@@ -59,9 +59,9 @@ var e = undefined;
>undefined : undefined
x = e;
>x = e : any
>x = e : undefined
>x : any
>e : any
>e : undefined
var e2: typeof undefined;
>e2 : any

View File

@@ -1,5 +1,5 @@
//// [assignmentLHSIsReference.ts]
var value;
var value: any;
// identifiers: variable and parameter
var x1: number;

View File

@@ -1,5 +1,5 @@
=== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts ===
var value;
var value: any;
>value : Symbol(value, Decl(assignmentLHSIsReference.ts, 0, 3))
// identifiers: variable and parameter

View File

@@ -1,5 +1,5 @@
=== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsReference.ts ===
var value;
var value: any;
>value : any
// identifiers: variable and parameter

View File

@@ -41,7 +41,7 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7
==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (39 errors) ====
// expected error for all the LHS of assignments
var value;
var value: any;
// this
class C {

View File

@@ -1,6 +1,6 @@
//// [assignmentLHSIsValue.ts]
// expected error for all the LHS of assignments
var value;
var value: any;
// this
class C {

View File

@@ -39,7 +39,7 @@ for (let x = 0; x < 1; ++x) {
}
switch (x) {
>x : any
>x : undefined
case 1:
>1 : 1

View File

@@ -40,7 +40,7 @@ for (let x = 0; x < 1; ++x) {
}
switch (x) {
>x : any
>x : undefined
case 1:
>1 : 1

View File

@@ -17,7 +17,7 @@ foo(/*c2*/ 1, /*d2*/ 1 + 2, /*e1*/ a + b);
>1 : 1
>2 : 2
>a + b : any
>a : any
>a : undefined
>b : any
foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b);
@@ -26,7 +26,7 @@ foo(/*c3*/ function () { }, /*d2*/() => { }, /*e2*/ a + /*e3*/ b);
>function () { } : () => void
>() => { } : () => void
>a + /*e3*/ b : any
>a : any
>a : undefined
>b : any
foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b));
@@ -36,7 +36,7 @@ foo(/*c3*/ function () { }, /*d3*/() => { }, /*e3*/(a + b));
>() => { } : () => void
>(a + b) : any
>a + b : any
>a : any
>a : undefined
>b : any
foo(

View File

@@ -9,12 +9,12 @@ var x1: number;
x1 *= value;
>x1 *= value : number
>x1 : number
>value : any
>value : undefined
x1 += value;
>x1 += value : any
>x1 += value : number
>x1 : number
>value : any
>value : undefined
function fn1(x2: number) {
>fn1 : (x2: number) => void
@@ -41,41 +41,41 @@ x3.a *= value;
>x3.a : number
>x3 : { a: number; }
>a : number
>value : any
>value : undefined
x3.a += value;
>x3.a += value : any
>x3.a += value : number
>x3.a : number
>x3 : { a: number; }
>a : number
>value : any
>value : undefined
x3['a'] *= value;
>x3['a'] *= value : number
>x3['a'] : number
>x3 : { a: number; }
>'a' : "a"
>value : any
>value : undefined
x3['a'] += value;
>x3['a'] += value : any
>x3['a'] += value : number
>x3['a'] : number
>x3 : { a: number; }
>'a' : "a"
>value : any
>value : undefined
// parentheses, the contained expression is reference
(x1) *= value;
>(x1) *= value : number
>(x1) : number
>x1 : number
>value : any
>value : undefined
(x1) += value;
>(x1) += value : any
>(x1) += value : number
>(x1) : number
>x1 : number
>value : any
>value : undefined
function fn2(x4: number) {
>fn2 : (x4: number) => void
@@ -100,15 +100,15 @@ function fn2(x4: number) {
>x3.a : number
>x3 : { a: number; }
>a : number
>value : any
>value : undefined
(x3.a) += value;
>(x3.a) += value : any
>(x3.a) += value : number
>(x3.a) : number
>x3.a : number
>x3 : { a: number; }
>a : number
>value : any
>value : undefined
(x3['a']) *= value;
>(x3['a']) *= value : number
@@ -116,13 +116,13 @@ function fn2(x4: number) {
>x3['a'] : number
>x3 : { a: number; }
>'a' : "a"
>value : any
>value : undefined
(x3['a']) += value;
>(x3['a']) += value : any
>(x3['a']) += value : number
>(x3['a']) : number
>x3['a'] : number
>x3 : { a: number; }
>'a' : "a"
>value : any
>value : undefined

View File

@@ -77,7 +77,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa
==== tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts (74 errors) ====
// expected error for all the LHS of compound assignments (arithmetic and addition)
var value;
var value: any;
// this
class C {

View File

@@ -1,7 +1,7 @@
//// [compoundAssignmentLHSIsValue.ts]
// expected error for all the LHS of compound assignments (arithmetic and addition)
var value;
var value: any;
// this
class C {

View File

@@ -1,5 +1,5 @@
//// [compoundExponentiationAssignmentLHSIsReference.ts]
var value;
var value: any;
// identifiers: variable and parameter
var x1: number;

View File

@@ -1,5 +1,5 @@
=== tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts ===
var value;
var value: any;
>value : Symbol(value, Decl(compoundExponentiationAssignmentLHSIsReference.ts, 0, 3))
// identifiers: variable and parameter

View File

@@ -1,5 +1,5 @@
=== tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsReference.ts ===
var value;
var value: any;
>value : any
// identifiers: variable and parameter

View File

@@ -40,7 +40,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm
==== tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts (38 errors) ====
// expected error for all the LHS of compound assignments (arithmetic and addition)
var value;
var value: any;
// this
class C {

View File

@@ -1,6 +1,6 @@
//// [compoundExponentiationAssignmentLHSIsValue.ts]
// expected error for all the LHS of compound assignments (arithmetic and addition)
var value;
var value: any;
// this
class C {

View File

@@ -35,20 +35,20 @@ var a;
>a : any
foo(a);
>foo(a) : any
>foo(a) : undefined
>foo : <T extends String>(x: T) => T
>a : any
>a : undefined
foo2(a);
>foo2(a) : any
>foo2(a) : undefined
>foo2 : <T extends { x: number; }>(x: T) => T
>a : any
>a : undefined
//foo3(a);
foo4(a);
>foo4(a) : any
>foo4(a) : undefined
>foo4 : <T extends <T>(x: T) => void>(x: T) => T
>a : any
>a : undefined
var b: number;
>b : number
@@ -84,10 +84,10 @@ class C<T extends String> {
}
var c1 = new C(a);
>c1 : C<any>
>new C(a) : C<any>
>c1 : C<undefined>
>new C(a) : C<undefined>
>C : typeof C
>a : any
>a : undefined
var c2 = new C<any>(b);
>c2 : C<any>
@@ -106,10 +106,10 @@ class C2<T extends { x: number }> {
}
var c3 = new C2(a);
>c3 : C2<any>
>new C2(a) : C2<any>
>c3 : C2<undefined>
>new C2(a) : C2<undefined>
>C2 : typeof C2
>a : any
>a : undefined
var c4 = new C2<any>(b);
>c4 : C2<any>
@@ -138,10 +138,10 @@ class C4<T extends <T>(x:T) => T> {
}
var c7 = new C4(a);
>c7 : C4<any>
>new C4(a) : C4<any>
>c7 : C4<undefined>
>new C4(a) : C4<undefined>
>C4 : typeof C4
>a : any
>a : undefined
var c8 = new C4<any>(b);
>c8 : C4<any>

View File

@@ -0,0 +1,128 @@
tests/cases/compiler/controlFlowCaching.ts(38,17): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(38,29): error TS2339: Property 'y' does not exist on type 'never'.
tests/cases/compiler/controlFlowCaching.ts(40,17): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(40,29): error TS2339: Property 'x' does not exist on type 'never'.
tests/cases/compiler/controlFlowCaching.ts(42,17): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(42,29): error TS2339: Property 'y' does not exist on type 'never'.
tests/cases/compiler/controlFlowCaching.ts(44,17): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(44,29): error TS2339: Property 'y' does not exist on type 'never'.
tests/cases/compiler/controlFlowCaching.ts(46,17): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(46,29): error TS2339: Property 'y' does not exist on type 'never'.
tests/cases/compiler/controlFlowCaching.ts(48,17): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(48,29): error TS2339: Property 'y' does not exist on type 'never'.
tests/cases/compiler/controlFlowCaching.ts(53,5): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(53,14): error TS2339: Property 'y' does not exist on type 'never'.
tests/cases/compiler/controlFlowCaching.ts(55,14): error TS2678: Type '"start"' is not comparable to type 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(58,14): error TS2678: Type '"end"' is not comparable to type 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(61,14): error TS2678: Type '"middle"' is not comparable to type 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(62,13): error TS2532: Object is possibly 'undefined'.
tests/cases/compiler/controlFlowCaching.ts(62,25): error TS2339: Property 'y' does not exist on type 'never'.
==== tests/cases/compiler/controlFlowCaching.ts (19 errors) ====
// Repro for #8401
function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) {
var isRtl = this._isRtl(); // chart mirroring
// prepare variable
var o = this.opt, ta = this.chart.theme.axis, position = o.position,
leftBottom = position !== "rightOrTop", rotation = o.rotation % 360,
start, stop, titlePos, titleRotation = 0, titleOffset, axisVector, tickVector, anchorOffset, labelOffset, labelAlign,
labelGap = this.chart.theme.axis.tick.labelGap,
taFont = o.font || (ta.majorTick && ta.majorTick.font) || (ta.tick && ta.tick.font),
taTitleFont = o.titleFont || (ta.title && ta.title.font),
taFontColor = o.fontColor || (ta.majorTick && ta.majorTick.fontColor) || (ta.tick && ta.tick.fontColor) || "black",
taTitleFontColor = o.titleFontColor || (ta.title && ta.title.fontColor) || "black",
taTitleGap = (o.titleGap == 0) ? 0 : o.titleGap || (ta.title && ta.title.gap) || 15,
taTitleOrientation = o.titleOrientation || (ta.title && ta.title.orientation) || "axis",
taMajorTick = this.chart.theme.getTick("major", o),
taMinorTick = this.chart.theme.getTick("minor", o),
taMicroTick = this.chart.theme.getTick("micro", o),
taStroke = "stroke" in o ? o.stroke : ta.stroke,
size = taFont ? g.normalizedLength(g.splitFontString(taFont).size) : 0,
cosr = Math.abs(Math.cos(rotation * Math.PI / 180)),
sinr = Math.abs(Math.sin(rotation * Math.PI / 180)),
tsize = taTitleFont ? g.normalizedLength(g.splitFontString(taTitleFont).size) : 0;
if (rotation < 0) {
rotation += 360;
}
var cachedLabelW = this._getMaxLabelSize();
cachedLabelW = cachedLabelW && cachedLabelW.majLabelW;
titleOffset = size * cosr + (cachedLabelW || 0) * sinr + labelGap + Math.max(taMajorTick.length > 0 ? taMajorTick.length : 0,
taMinorTick.length > 0 ? taMinorTick.length : 0) +
tsize + taTitleGap;
axisVector = { x: isRtl ? -1 : 1, y: 0 }; // chart mirroring
switch (rotation) {
default:
if (rotation < (90 - centerAnchorLimit)) {
labelOffset.y = leftBottom ? size : 0;
~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
~
!!! error TS2339: Property 'y' does not exist on type 'never'.
} else if (rotation < (90 + centerAnchorLimit)) {
labelOffset.x = -size * 0.4;
~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
~
!!! error TS2339: Property 'x' does not exist on type 'never'.
} else if (rotation < 180) {
labelOffset.y = leftBottom ? 0 : -size;
~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
~
!!! error TS2339: Property 'y' does not exist on type 'never'.
} else if (rotation < (270 - centerAnchorLimit)) {
labelOffset.y = leftBottom ? 0 : -size;
~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
~
!!! error TS2339: Property 'y' does not exist on type 'never'.
} else if (rotation < (270 + centerAnchorLimit)) {
labelOffset.y = leftBottom ? size * 0.4 : 0;
~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
~
!!! error TS2339: Property 'y' does not exist on type 'never'.
} else {
labelOffset.y = leftBottom ? size : 0;
~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
~
!!! error TS2339: Property 'y' does not exist on type 'never'.
}
}
titleRotation = (taTitleOrientation && taTitleOrientation == "away") ? 180 : 0;
titlePos.y = offsets.t - titleOffset + (titleRotation ? 0 : tsize);
~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
~
!!! error TS2339: Property 'y' does not exist on type 'never'.
switch (labelAlign) {
case "start":
~~~~~~~
!!! error TS2678: Type '"start"' is not comparable to type 'undefined'.
labelAlign = "end";
break;
case "end":
~~~~~
!!! error TS2678: Type '"end"' is not comparable to type 'undefined'.
labelAlign = "start";
break;
case "middle":
~~~~~~~~
!!! error TS2678: Type '"middle"' is not comparable to type 'undefined'.
labelOffset.y -= size;
~~~~~~~~~~~
!!! error TS2532: Object is possibly 'undefined'.
~
!!! error TS2339: Property 'y' does not exist on type 'never'.
break;
}
let _ = rotation;
}

View File

@@ -118,7 +118,7 @@ maybeNumber++;
if (maybeNumber !== undefined) {
>maybeNumber !== undefined : boolean
>maybeNumber : number | undefined
>maybeNumber : number
>undefined : undefined
maybeNumber++;

View File

@@ -0,0 +1,247 @@
//// [controlFlowLetVar.ts]
declare let cond: boolean;
// CFA for 'let' with no type annotation and initializer
function f1() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'undefined' initializer
function f2() {
let x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'null' initializer
function f3() {
let x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | null
}
// No CFA for 'let' with with type annotation
function f4() {
let x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// CFA for 'var' with no type annotation and initializer
function f5() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'undefined' initializer
function f6() {
var x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'null' initializer
function f7() {
var x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | null
}
// No CFA for 'var' with with type annotation
function f8() {
var x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// No CFA for captured outer variables
function f9() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
function f() {
const z = x; // any
}
}
// No CFA for captured outer variables
function f10() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
const f = () => {
const z = x; // any
};
}
//// [controlFlowLetVar.js]
// CFA for 'let' with no type annotation and initializer
function f1() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'undefined' initializer
function f2() {
var x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'null' initializer
function f3() {
var x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | null
}
// No CFA for 'let' with with type annotation
function f4() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // any
}
// CFA for 'var' with no type annotation and initializer
function f5() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'undefined' initializer
function f6() {
var x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'null' initializer
function f7() {
var x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | null
}
// No CFA for 'var' with with type annotation
function f8() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // any
}
// No CFA for captured outer variables
function f9() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
function f() {
var z = x; // any
}
}
// No CFA for captured outer variables
function f10() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
var f = function () {
var z = x; // any
};
}

View File

@@ -0,0 +1,263 @@
=== tests/cases/compiler/controlFlowLetVar.ts ===
declare let cond: boolean;
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
// CFA for 'let' with no type annotation and initializer
function f1() {
>f1 : Symbol(f1, Decl(controlFlowLetVar.ts, 1, 26))
let x;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7))
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = 1;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7))
}
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = "hello";
>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7))
}
const y = x; // string | number | undefined
>y : Symbol(y, Decl(controlFlowLetVar.ts, 12, 9))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 5, 7))
}
// CFA for 'let' with no type annotation and 'undefined' initializer
function f2() {
>f2 : Symbol(f2, Decl(controlFlowLetVar.ts, 13, 1))
let x = undefined;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7))
>undefined : Symbol(undefined)
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = 1;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7))
}
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = "hello";
>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7))
}
const y = x; // string | number | undefined
>y : Symbol(y, Decl(controlFlowLetVar.ts, 24, 9))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 17, 7))
}
// CFA for 'let' with no type annotation and 'null' initializer
function f3() {
>f3 : Symbol(f3, Decl(controlFlowLetVar.ts, 25, 1))
let x = null;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7))
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = 1;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7))
}
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = "hello";
>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7))
}
const y = x; // string | number | null
>y : Symbol(y, Decl(controlFlowLetVar.ts, 36, 9))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 29, 7))
}
// No CFA for 'let' with with type annotation
function f4() {
>f4 : Symbol(f4, Decl(controlFlowLetVar.ts, 37, 1))
let x: any;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7))
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = 1;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7))
}
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = "hello";
>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7))
}
const y = x; // any
>y : Symbol(y, Decl(controlFlowLetVar.ts, 48, 9))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 41, 7))
}
// CFA for 'var' with no type annotation and initializer
function f5() {
>f5 : Symbol(f5, Decl(controlFlowLetVar.ts, 49, 1))
var x;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7))
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = 1;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7))
}
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = "hello";
>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7))
}
const y = x; // string | number | undefined
>y : Symbol(y, Decl(controlFlowLetVar.ts, 60, 9))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 53, 7))
}
// CFA for 'var' with no type annotation and 'undefined' initializer
function f6() {
>f6 : Symbol(f6, Decl(controlFlowLetVar.ts, 61, 1))
var x = undefined;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7))
>undefined : Symbol(undefined)
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = 1;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7))
}
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = "hello";
>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7))
}
const y = x; // string | number | undefined
>y : Symbol(y, Decl(controlFlowLetVar.ts, 72, 9))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 65, 7))
}
// CFA for 'var' with no type annotation and 'null' initializer
function f7() {
>f7 : Symbol(f7, Decl(controlFlowLetVar.ts, 73, 1))
var x = null;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7))
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = 1;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7))
}
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = "hello";
>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7))
}
const y = x; // string | number | null
>y : Symbol(y, Decl(controlFlowLetVar.ts, 84, 9))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 77, 7))
}
// No CFA for 'var' with with type annotation
function f8() {
>f8 : Symbol(f8, Decl(controlFlowLetVar.ts, 85, 1))
var x: any;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7))
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = 1;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7))
}
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = "hello";
>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7))
}
const y = x; // any
>y : Symbol(y, Decl(controlFlowLetVar.ts, 96, 9))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 89, 7))
}
// No CFA for captured outer variables
function f9() {
>f9 : Symbol(f9, Decl(controlFlowLetVar.ts, 97, 1))
let x;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7))
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = 1;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7))
}
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = "hello";
>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7))
}
const y = x; // string | number | undefined
>y : Symbol(y, Decl(controlFlowLetVar.ts, 108, 9))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7))
function f() {
>f : Symbol(f, Decl(controlFlowLetVar.ts, 108, 16))
const z = x; // any
>z : Symbol(z, Decl(controlFlowLetVar.ts, 110, 13))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 101, 7))
}
}
// No CFA for captured outer variables
function f10() {
>f10 : Symbol(f10, Decl(controlFlowLetVar.ts, 112, 1))
let x;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7))
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = 1;
>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7))
}
if (cond) {
>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11))
x = "hello";
>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7))
}
const y = x; // string | number | undefined
>y : Symbol(y, Decl(controlFlowLetVar.ts, 123, 9))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7))
const f = () => {
>f : Symbol(f, Decl(controlFlowLetVar.ts, 124, 9))
const z = x; // any
>z : Symbol(z, Decl(controlFlowLetVar.ts, 125, 13))
>x : Symbol(x, Decl(controlFlowLetVar.ts, 116, 7))
};
}

View File

@@ -0,0 +1,306 @@
=== tests/cases/compiler/controlFlowLetVar.ts ===
declare let cond: boolean;
>cond : boolean
// CFA for 'let' with no type annotation and initializer
function f1() {
>f1 : () => void
let x;
>x : any
if (cond) {
>cond : boolean
x = 1;
>x = 1 : 1
>x : any
>1 : 1
}
if (cond) {
>cond : boolean
x = "hello";
>x = "hello" : "hello"
>x : any
>"hello" : "hello"
}
const y = x; // string | number | undefined
>y : string | number | undefined
>x : string | number | undefined
}
// CFA for 'let' with no type annotation and 'undefined' initializer
function f2() {
>f2 : () => void
let x = undefined;
>x : any
>undefined : undefined
if (cond) {
>cond : boolean
x = 1;
>x = 1 : 1
>x : any
>1 : 1
}
if (cond) {
>cond : boolean
x = "hello";
>x = "hello" : "hello"
>x : any
>"hello" : "hello"
}
const y = x; // string | number | undefined
>y : string | number | undefined
>x : string | number | undefined
}
// CFA for 'let' with no type annotation and 'null' initializer
function f3() {
>f3 : () => void
let x = null;
>x : any
>null : null
if (cond) {
>cond : boolean
x = 1;
>x = 1 : 1
>x : any
>1 : 1
}
if (cond) {
>cond : boolean
x = "hello";
>x = "hello" : "hello"
>x : any
>"hello" : "hello"
}
const y = x; // string | number | null
>y : string | number | null
>x : string | number | null
}
// No CFA for 'let' with with type annotation
function f4() {
>f4 : () => void
let x: any;
>x : any
if (cond) {
>cond : boolean
x = 1;
>x = 1 : 1
>x : any
>1 : 1
}
if (cond) {
>cond : boolean
x = "hello";
>x = "hello" : "hello"
>x : any
>"hello" : "hello"
}
const y = x; // any
>y : any
>x : any
}
// CFA for 'var' with no type annotation and initializer
function f5() {
>f5 : () => void
var x;
>x : any
if (cond) {
>cond : boolean
x = 1;
>x = 1 : 1
>x : any
>1 : 1
}
if (cond) {
>cond : boolean
x = "hello";
>x = "hello" : "hello"
>x : any
>"hello" : "hello"
}
const y = x; // string | number | undefined
>y : string | number | undefined
>x : string | number | undefined
}
// CFA for 'var' with no type annotation and 'undefined' initializer
function f6() {
>f6 : () => void
var x = undefined;
>x : any
>undefined : undefined
if (cond) {
>cond : boolean
x = 1;
>x = 1 : 1
>x : any
>1 : 1
}
if (cond) {
>cond : boolean
x = "hello";
>x = "hello" : "hello"
>x : any
>"hello" : "hello"
}
const y = x; // string | number | undefined
>y : string | number | undefined
>x : string | number | undefined
}
// CFA for 'var' with no type annotation and 'null' initializer
function f7() {
>f7 : () => void
var x = null;
>x : any
>null : null
if (cond) {
>cond : boolean
x = 1;
>x = 1 : 1
>x : any
>1 : 1
}
if (cond) {
>cond : boolean
x = "hello";
>x = "hello" : "hello"
>x : any
>"hello" : "hello"
}
const y = x; // string | number | null
>y : string | number | null
>x : string | number | null
}
// No CFA for 'var' with with type annotation
function f8() {
>f8 : () => void
var x: any;
>x : any
if (cond) {
>cond : boolean
x = 1;
>x = 1 : 1
>x : any
>1 : 1
}
if (cond) {
>cond : boolean
x = "hello";
>x = "hello" : "hello"
>x : any
>"hello" : "hello"
}
const y = x; // any
>y : any
>x : any
}
// No CFA for captured outer variables
function f9() {
>f9 : () => void
let x;
>x : any
if (cond) {
>cond : boolean
x = 1;
>x = 1 : 1
>x : any
>1 : 1
}
if (cond) {
>cond : boolean
x = "hello";
>x = "hello" : "hello"
>x : any
>"hello" : "hello"
}
const y = x; // string | number | undefined
>y : string | number | undefined
>x : string | number | undefined
function f() {
>f : () => void
const z = x; // any
>z : any
>x : any
}
}
// No CFA for captured outer variables
function f10() {
>f10 : () => void
let x;
>x : any
if (cond) {
>cond : boolean
x = 1;
>x = 1 : 1
>x : any
>1 : 1
}
if (cond) {
>cond : boolean
x = "hello";
>x = "hello" : "hello"
>x : any
>"hello" : "hello"
}
const y = x; // string | number | undefined
>y : string | number | undefined
>x : string | number | undefined
const f = () => {
>f : () => void
>() => { const z = x; // any } : () => void
const z = x; // any
>z : any
>x : any
};
}

View File

@@ -0,0 +1,143 @@
tests/cases/compiler/controlFlowNoImplicitAny.ts(102,9): error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined.
tests/cases/compiler/controlFlowNoImplicitAny.ts(111,19): error TS7005: Variable 'x' implicitly has an 'any' type.
tests/cases/compiler/controlFlowNoImplicitAny.ts(117,9): error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined.
tests/cases/compiler/controlFlowNoImplicitAny.ts(126,19): error TS7005: Variable 'x' implicitly has an 'any' type.
==== tests/cases/compiler/controlFlowNoImplicitAny.ts (4 errors) ====
declare let cond: boolean;
// CFA for 'let' with no type annotation and initializer
function f1() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'undefined' initializer
function f2() {
let x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'null' initializer
function f3() {
let x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | null
}
// No CFA for 'let' with with type annotation
function f4() {
let x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// CFA for 'var' with no type annotation and initializer
function f5() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'undefined' initializer
function f6() {
var x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'null' initializer
function f7() {
var x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | null
}
// No CFA for 'var' with with type annotation
function f8() {
var x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// No CFA for captured outer variables
function f9() {
let x;
~
!!! error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined.
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
function f() {
const z = x; // any
~
!!! error TS7005: Variable 'x' implicitly has an 'any' type.
}
}
// No CFA for captured outer variables
function f10() {
let x;
~
!!! error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined.
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
const f = () => {
const z = x; // any
~
!!! error TS7005: Variable 'x' implicitly has an 'any' type.
};
}

View File

@@ -0,0 +1,247 @@
//// [controlFlowNoImplicitAny.ts]
declare let cond: boolean;
// CFA for 'let' with no type annotation and initializer
function f1() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'undefined' initializer
function f2() {
let x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'null' initializer
function f3() {
let x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | null
}
// No CFA for 'let' with with type annotation
function f4() {
let x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// CFA for 'var' with no type annotation and initializer
function f5() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'undefined' initializer
function f6() {
var x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'null' initializer
function f7() {
var x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | null
}
// No CFA for 'var' with with type annotation
function f8() {
var x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// No CFA for captured outer variables
function f9() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
function f() {
const z = x; // any
}
}
// No CFA for captured outer variables
function f10() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
const f = () => {
const z = x; // any
};
}
//// [controlFlowNoImplicitAny.js]
// CFA for 'let' with no type annotation and initializer
function f1() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'undefined' initializer
function f2() {
var x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'null' initializer
function f3() {
var x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | null
}
// No CFA for 'let' with with type annotation
function f4() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // any
}
// CFA for 'var' with no type annotation and initializer
function f5() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'undefined' initializer
function f6() {
var x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'null' initializer
function f7() {
var x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | null
}
// No CFA for 'var' with with type annotation
function f8() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // any
}
// No CFA for captured outer variables
function f9() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
function f() {
var z = x; // any
}
}
// No CFA for captured outer variables
function f10() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
var y = x; // string | number | undefined
var f = function () {
var z = x; // any
};
}

View File

@@ -2,7 +2,7 @@
// -- operator on any type
var ANY: any;
var ANY1;
var ANY1: any;
var ANY2: any[] = ["", ""];
var obj = {x:1,y:null};
class A {

View File

@@ -4,7 +4,7 @@
var ANY: any;
>ANY : Symbol(ANY, Decl(decrementOperatorWithAnyOtherType.ts, 2, 3))
var ANY1;
var ANY1: any;
>ANY1 : Symbol(ANY1, Decl(decrementOperatorWithAnyOtherType.ts, 3, 3))
var ANY2: any[] = ["", ""];

View File

@@ -4,7 +4,7 @@
var ANY: any;
>ANY : any
var ANY1;
var ANY1: any;
>ANY1 : any
var ANY2: any[] = ["", ""];

View File

@@ -52,7 +52,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp
==== tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOperatorWithAnyOtherTypeInvalidOperations.ts (50 errors) ====
// -- operator on any type
var ANY1;
var ANY1: any;
var ANY2: any[] = ["", ""];
var obj: () => {}
@@ -63,7 +63,7 @@ tests/cases/conformance/expressions/unaryOperators/decrementOperator/decrementOp
}
class A {
public a: any;
static foo() {
static foo(): any {
var a;
return a;
}

View File

@@ -1,6 +1,6 @@
//// [decrementOperatorWithAnyOtherTypeInvalidOperations.ts]
// -- operator on any type
var ANY1;
var ANY1: any;
var ANY2: any[] = ["", ""];
var obj: () => {}
@@ -11,7 +11,7 @@ function foo(): any {
}
class A {
public a: any;
static foo() {
static foo(): any {
var a;
return a;
}

View File

@@ -77,22 +77,22 @@ use(x);
use(z0);
>use(z0) : any
>use : (a: any) => any
>z0 : any
>z0 : undefined
use(z1);
>use(z1) : any
>use : (a: any) => any
>z1 : any
>z1 : undefined
use(z2);
>use(z2) : any
>use : (a: any) => any
>z2 : any
>z2 : undefined
use(z3);
>use(z3) : any
>use : (a: any) => any
>z3 : any
>z3 : undefined
var z6;
>z6 : any
@@ -149,7 +149,7 @@ use(y);
use(z6);
>use(z6) : any
>use : (a: any) => any
>z6 : any
>z6 : undefined
var z = false;
>z : boolean

View File

@@ -83,22 +83,22 @@ use(x);
use(z0);
>use(z0) : any
>use : (a: any) => any
>z0 : any
>z0 : undefined
use(z1);
>use(z1) : any
>use : (a: any) => any
>z1 : any
>z1 : undefined
use(z2);
>use(z2) : any
>use : (a: any) => any
>z2 : any
>z2 : undefined
use(z3);
>use(z3) : any
>use : (a: any) => any
>z3 : any
>z3 : undefined
var z6;
>z6 : any
@@ -155,7 +155,7 @@ use(y);
use(z6);
>use(z6) : any
>use : (a: any) => any
>z6 : any
>z6 : undefined
var z = false;
>z : boolean

View File

@@ -1,8 +1,8 @@
//// [es5-asyncFunctionTryStatements.ts]
declare var x, y, z, a, b, c;
declare var x: any, y: any, z: any, a: any, b: any, c: any;
async function tryCatch0() {
var x, y;
var x: any, y: any;
try {
x;
}
@@ -12,7 +12,7 @@ async function tryCatch0() {
}
async function tryCatch1() {
var x, y;
var x: any, y: any;
try {
await x;
}
@@ -22,7 +22,7 @@ async function tryCatch1() {
}
async function tryCatch2() {
var x, y;
var x: any, y: any;
try {
x;
}
@@ -32,7 +32,7 @@ async function tryCatch2() {
}
async function tryCatch3(): Promise<Function> {
var x, y;
var x: any, y: any;
try {
await x;
}
@@ -41,7 +41,7 @@ async function tryCatch3(): Promise<Function> {
}
}
async function tryFinally0() {
var x, y;
var x: any, y: any;
try {
x;
}
@@ -51,7 +51,7 @@ async function tryFinally0() {
}
async function tryFinally1() {
var x, y;
var x: any, y: any;
try {
await x;
}
@@ -61,7 +61,7 @@ async function tryFinally1() {
}
async function tryFinally2() {
var x, y;
var x: any, y: any;
try {
x;
}
@@ -71,7 +71,7 @@ async function tryFinally2() {
}
async function tryCatchFinally0() {
var x, y, z;
var x: any, y: any, z: any;
try {
x;
}
@@ -84,7 +84,7 @@ async function tryCatchFinally0() {
}
async function tryCatchFinally1() {
var x, y, z;
var x: any, y: any, z: any;
try {
await x;
}
@@ -97,7 +97,7 @@ async function tryCatchFinally1() {
}
async function tryCatchFinally2() {
var x, y, z;
var x: any, y: any, z: any;
try {
x;
}
@@ -110,7 +110,7 @@ async function tryCatchFinally2() {
}
async function tryCatchFinally3() {
var x, y, z;
var x: any, y: any, z: any;
try {
x;
}

View File

@@ -1,18 +1,18 @@
=== tests/cases/compiler/es5-asyncFunctionTryStatements.ts ===
declare var x, y, z, a, b, c;
declare var x: any, y: any, z: any, a: any, b: any, c: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 0, 11))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 0, 14))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 0, 17))
>a : Symbol(a, Decl(es5-asyncFunctionTryStatements.ts, 0, 20))
>b : Symbol(b, Decl(es5-asyncFunctionTryStatements.ts, 0, 23))
>c : Symbol(c, Decl(es5-asyncFunctionTryStatements.ts, 0, 26))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 0, 19))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 0, 27))
>a : Symbol(a, Decl(es5-asyncFunctionTryStatements.ts, 0, 35))
>b : Symbol(b, Decl(es5-asyncFunctionTryStatements.ts, 0, 43))
>c : Symbol(c, Decl(es5-asyncFunctionTryStatements.ts, 0, 51))
async function tryCatch0() {
>tryCatch0 : Symbol(tryCatch0, Decl(es5-asyncFunctionTryStatements.ts, 0, 29))
>tryCatch0 : Symbol(tryCatch0, Decl(es5-asyncFunctionTryStatements.ts, 0, 59))
var x, y;
var x: any, y: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 3, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 15))
try {
x;
@@ -22,16 +22,16 @@ async function tryCatch0() {
>e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 7, 11))
y;
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 3, 15))
}
}
async function tryCatch1() {
>tryCatch1 : Symbol(tryCatch1, Decl(es5-asyncFunctionTryStatements.ts, 10, 1))
var x, y;
var x: any, y: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 13, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 15))
try {
await x;
@@ -41,16 +41,16 @@ async function tryCatch1() {
>e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 17, 11))
y;
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 13, 15))
}
}
async function tryCatch2() {
>tryCatch2 : Symbol(tryCatch2, Decl(es5-asyncFunctionTryStatements.ts, 20, 1))
var x, y;
var x: any, y: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 23, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 15))
try {
x;
@@ -60,7 +60,7 @@ async function tryCatch2() {
>e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 27, 11))
await y;
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 23, 15))
}
}
@@ -69,9 +69,9 @@ async function tryCatch3(): Promise<Function> {
>Promise : Symbol(Promise, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
var x, y;
var x: any, y: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 33, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 33, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 33, 15))
try {
await x;
@@ -87,9 +87,9 @@ async function tryCatch3(): Promise<Function> {
async function tryFinally0() {
>tryFinally0 : Symbol(tryFinally0, Decl(es5-asyncFunctionTryStatements.ts, 40, 1))
var x, y;
var x: any, y: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 42, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 15))
try {
x;
@@ -97,16 +97,16 @@ async function tryFinally0() {
}
finally {
y;
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 42, 15))
}
}
async function tryFinally1() {
>tryFinally1 : Symbol(tryFinally1, Decl(es5-asyncFunctionTryStatements.ts, 49, 1))
var x, y;
var x: any, y: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 52, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 15))
try {
await x;
@@ -114,16 +114,16 @@ async function tryFinally1() {
}
finally {
y;
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 52, 15))
}
}
async function tryFinally2() {
>tryFinally2 : Symbol(tryFinally2, Decl(es5-asyncFunctionTryStatements.ts, 59, 1))
var x, y;
var x: any, y: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 62, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 15))
try {
x;
@@ -131,17 +131,17 @@ async function tryFinally2() {
}
finally {
await y;
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 62, 15))
}
}
async function tryCatchFinally0() {
>tryCatchFinally0 : Symbol(tryCatchFinally0, Decl(es5-asyncFunctionTryStatements.ts, 69, 1))
var x, y, z;
var x: any, y: any, z: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 72, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 10))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 13))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 15))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 23))
try {
x;
@@ -151,21 +151,21 @@ async function tryCatchFinally0() {
>e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 76, 11))
y;
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 72, 15))
}
finally {
z;
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 13))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 72, 23))
}
}
async function tryCatchFinally1() {
>tryCatchFinally1 : Symbol(tryCatchFinally1, Decl(es5-asyncFunctionTryStatements.ts, 82, 1))
var x, y, z;
var x: any, y: any, z: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 85, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 10))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 13))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 15))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 23))
try {
await x;
@@ -175,21 +175,21 @@ async function tryCatchFinally1() {
>e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 89, 11))
y;
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 85, 15))
}
finally {
z;
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 13))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 85, 23))
}
}
async function tryCatchFinally2() {
>tryCatchFinally2 : Symbol(tryCatchFinally2, Decl(es5-asyncFunctionTryStatements.ts, 95, 1))
var x, y, z;
var x: any, y: any, z: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 98, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 10))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 13))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 15))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 23))
try {
x;
@@ -199,21 +199,21 @@ async function tryCatchFinally2() {
>e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 102, 11))
await y;
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 98, 15))
}
finally {
z;
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 13))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 98, 23))
}
}
async function tryCatchFinally3() {
>tryCatchFinally3 : Symbol(tryCatchFinally3, Decl(es5-asyncFunctionTryStatements.ts, 108, 1))
var x, y, z;
var x: any, y: any, z: any;
>x : Symbol(x, Decl(es5-asyncFunctionTryStatements.ts, 111, 7))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 10))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 13))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 15))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 23))
try {
x;
@@ -223,10 +223,10 @@ async function tryCatchFinally3() {
>e : Symbol(e, Decl(es5-asyncFunctionTryStatements.ts, 115, 11))
y;
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 10))
>y : Symbol(y, Decl(es5-asyncFunctionTryStatements.ts, 111, 15))
}
finally {
await z;
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 13))
>z : Symbol(z, Decl(es5-asyncFunctionTryStatements.ts, 111, 23))
}
}

View File

@@ -1,5 +1,5 @@
=== tests/cases/compiler/es5-asyncFunctionTryStatements.ts ===
declare var x, y, z, a, b, c;
declare var x: any, y: any, z: any, a: any, b: any, c: any;
>x : any
>y : any
>z : any
@@ -10,7 +10,7 @@ declare var x, y, z, a, b, c;
async function tryCatch0() {
>tryCatch0 : () => Promise<void>
var x, y;
var x: any, y: any;
>x : any
>y : any
@@ -29,7 +29,7 @@ async function tryCatch0() {
async function tryCatch1() {
>tryCatch1 : () => Promise<void>
var x, y;
var x: any, y: any;
>x : any
>y : any
@@ -49,7 +49,7 @@ async function tryCatch1() {
async function tryCatch2() {
>tryCatch2 : () => Promise<void>
var x, y;
var x: any, y: any;
>x : any
>y : any
@@ -71,7 +71,7 @@ async function tryCatch3(): Promise<Function> {
>Promise : Promise<T>
>Function : Function
var x, y;
var x: any, y: any;
>x : any
>y : any
@@ -91,7 +91,7 @@ async function tryCatch3(): Promise<Function> {
async function tryFinally0() {
>tryFinally0 : () => Promise<void>
var x, y;
var x: any, y: any;
>x : any
>y : any
@@ -108,7 +108,7 @@ async function tryFinally0() {
async function tryFinally1() {
>tryFinally1 : () => Promise<void>
var x, y;
var x: any, y: any;
>x : any
>y : any
@@ -126,7 +126,7 @@ async function tryFinally1() {
async function tryFinally2() {
>tryFinally2 : () => Promise<void>
var x, y;
var x: any, y: any;
>x : any
>y : any
@@ -144,7 +144,7 @@ async function tryFinally2() {
async function tryCatchFinally0() {
>tryCatchFinally0 : () => Promise<void>
var x, y, z;
var x: any, y: any, z: any;
>x : any
>y : any
>z : any
@@ -168,7 +168,7 @@ async function tryCatchFinally0() {
async function tryCatchFinally1() {
>tryCatchFinally1 : () => Promise<void>
var x, y, z;
var x: any, y: any, z: any;
>x : any
>y : any
>z : any
@@ -193,7 +193,7 @@ async function tryCatchFinally1() {
async function tryCatchFinally2() {
>tryCatchFinally2 : () => Promise<void>
var x, y, z;
var x: any, y: any, z: any;
>x : any
>y : any
>z : any
@@ -218,7 +218,7 @@ async function tryCatchFinally2() {
async function tryCatchFinally3() {
>tryCatchFinally3 : () => Promise<void>
var x, y, z;
var x: any, y: any, z: any;
>x : any
>y : any
>z : any

View File

@@ -84,7 +84,7 @@ tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxE
==== tests/cases/conformance/es7/exponentiationOperator/exponentiationOperatorSyntaxError2.ts (81 errors) ====
// Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without ()
var temp;
var temp: any;
delete --temp ** 3;
~~~~~~~~~~~~~

View File

@@ -1,7 +1,7 @@
//// [exponentiationOperatorSyntaxError2.ts]
// Error: early syntax error using ES7 SimpleUnaryExpression on left-hand side without ()
var temp;
var temp: any;
delete --temp ** 3;
delete ++temp ** 3;

View File

@@ -78,7 +78,7 @@ tests/cases/compiler/expr.ts(242,7): error TS2363: The right-hand side of an ari
}
function f() {
var a;
var a: any;
var n=3;
var s="";
var b=false;

View File

@@ -7,7 +7,7 @@ enum E {
}
function f() {
var a;
var a: any;
var n=3;
var s="";
var b=false;

View File

@@ -18,7 +18,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15):
for (var x in /[a-z]/) { }
for (var x in new Date()) { }
var c, d, e;
var c: any, d: any, e: any;
for (var x in c || d) { }
for (var x in e ? c : d) { }

View File

@@ -15,7 +15,7 @@ for (var x in fn()) { }
for (var x in /[a-z]/) { }
for (var x in new Date()) { }
var c, d, e;
var c: any, d: any, e: any;
for (var x in c || d) { }
for (var x in e ? c : d) { }

View File

@@ -2,7 +2,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of3.ts(2,6): error TS2487: Inva
==== tests/cases/conformance/es6/for-ofStatements/for-of3.ts (1 errors) ====
var v;
var v: any;
for (v++ of []) { }
~~~
!!! error TS2487: Invalid left-hand side in 'for...of' statement.

View File

@@ -1,5 +1,5 @@
//// [for-of3.ts]
var v;
var v: any;
for (v++ of []) { }
//// [for-of3.js]

View File

@@ -1,17 +1,24 @@
tests/cases/compiler/forIn.ts(2,10): error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation.
tests/cases/compiler/forIn.ts(2,22): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.
tests/cases/compiler/forIn.ts(7,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.
tests/cases/compiler/forIn.ts(18,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.
tests/cases/compiler/forIn.ts(20,4): error TS2304: Cannot find name 'k'.
==== tests/cases/compiler/forIn.ts (2 errors) ====
==== tests/cases/compiler/forIn.ts (5 errors) ====
var arr = null;
for (var i:number in arr) { // error
~
!!! error TS2404: The left-hand side of a 'for...in' statement cannot use a type annotation.
~~~
!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.
var x1 = arr[i];
var y1 = arr[i];
}
for (var j in arr) { // ok
~~~
!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.
var x2 = arr[j];
var y2 = arr[j];
}
@@ -23,6 +30,8 @@ tests/cases/compiler/forIn.ts(20,4): error TS2304: Cannot find name 'k'.
}
for (var l in arr) {
~~~
!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.
// error in the body
k[l] = 1;
~

View File

@@ -1,19 +1,23 @@
tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(2,5): error TS7005: Variable 'x' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(3,13): error TS7005: Variable 'foo' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(4,15): error TS7006: Parameter 'k' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(3,5): error TS7034: Variable 'y' implicitly has type 'any' in some locations where its type cannot be determined.
tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(4,13): error TS7005: Variable 'foo' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(5,15): error TS7006: Parameter 'k' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts(5,20): error TS7005: Variable 'y' implicitly has an 'any' type.
==== tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts (3 errors) ====
==== tests/cases/compiler/implicitAnyDeclareVariablesWithoutTypeAndInit.ts (4 errors) ====
// this should be an error
var x; // error at "x"
var x; // no error, control flow typed
var y; // error because captured
~
!!! error TS7005: Variable 'x' implicitly has an 'any' type.
declare var foo; // error at "foo"
!!! error TS7034: Variable 'y' implicitly has type 'any' in some locations where its type cannot be determined.
declare var foo; // error at "foo"
~~~
!!! error TS7005: Variable 'foo' implicitly has an 'any' type.
function func(k) { }; //error at "k"
function func(k) { y }; // error at "k"
~
!!! error TS7006: Parameter 'k' implicitly has an 'any' type.
~
!!! error TS7005: Variable 'y' implicitly has an 'any' type.
func(x);
// this shouldn't be an error

View File

@@ -1,8 +1,9 @@
//// [implicitAnyDeclareVariablesWithoutTypeAndInit.ts]
// this should be an error
var x; // error at "x"
declare var foo; // error at "foo"
function func(k) { }; //error at "k"
var x; // no error, control flow typed
var y; // error because captured
declare var foo; // error at "foo"
function func(k) { y }; // error at "k"
func(x);
// this shouldn't be an error
@@ -13,9 +14,10 @@ var x1: any; var y1 = new x1;
//// [implicitAnyDeclareVariablesWithoutTypeAndInit.js]
// this should be an error
var x; // error at "x"
function func(k) { }
; //error at "k"
var x; // no error, control flow typed
var y; // error because captured
function func(k) { y; }
; // error at "k"
func(x);
// this shouldn't be an error
var bar = 3;

View File

@@ -1,4 +1,3 @@
tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(2,5): error TS7005: Variable 'arg0' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(3,5): error TS7005: Variable 'anyArray' implicitly has an 'any[]' type.
tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(4,13): error TS7008: Member 'v' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(4,16): error TS7008: Member 'w' implicitly has an 'any' type.
@@ -7,11 +6,9 @@ tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(6,16): er
tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts(10,36): error TS7006: Parameter 'y2' implicitly has an 'any' type.
==== tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts (7 errors) ====
==== tests/cases/compiler/implicitAnyFunctionInvocationWithAnyArguements.ts (6 errors) ====
// this should be errors
var arg0 = null; // error at "arg0"
~~~~
!!! error TS7005: Variable 'arg0' implicitly has an 'any' type.
var anyArray = [null, undefined]; // error at array literal
~~~~~~~~
!!! error TS7005: Variable 'anyArray' implicitly has an 'any[]' type.

View File

@@ -1,17 +1,11 @@
tests/cases/compiler/implicitAnyWidenToAny.ts(2,5): error TS7005: Variable 'x' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyWidenToAny.ts(3,5): error TS7005: Variable 'x1' implicitly has an 'any' type.
tests/cases/compiler/implicitAnyWidenToAny.ts(4,5): error TS7005: Variable 'widenArray' implicitly has an 'any[]' type.
tests/cases/compiler/implicitAnyWidenToAny.ts(5,5): error TS7005: Variable 'emptyArray' implicitly has an 'any[]' type.
==== tests/cases/compiler/implicitAnyWidenToAny.ts (4 errors) ====
==== tests/cases/compiler/implicitAnyWidenToAny.ts (2 errors) ====
// these should be errors
var x = null; // error at "x"
~
!!! error TS7005: Variable 'x' implicitly has an 'any' type.
var x1 = undefined; // error at "x1"
~~
!!! error TS7005: Variable 'x1' implicitly has an 'any' type.
var widenArray = [null, undefined]; // error at "widenArray"
~~~~~~~~~~
!!! error TS7005: Variable 'widenArray' implicitly has an 'any[]' type.

View File

@@ -2,7 +2,7 @@
// ++ operator on any type
var ANY: any;
var ANY1;
var ANY1: any;
var ANY2: any[] = ["", ""];
var obj = {x:1,y:null};
class A {

View File

@@ -4,7 +4,7 @@
var ANY: any;
>ANY : Symbol(ANY, Decl(incrementOperatorWithAnyOtherType.ts, 2, 3))
var ANY1;
var ANY1: any;
>ANY1 : Symbol(ANY1, Decl(incrementOperatorWithAnyOtherType.ts, 3, 3))
var ANY2: any[] = ["", ""];

View File

@@ -4,7 +4,7 @@
var ANY: any;
>ANY : any
var ANY1;
var ANY1: any;
>ANY1 : any
var ANY2: any[] = ["", ""];

View File

@@ -47,7 +47,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp
==== tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOperatorWithAnyOtherTypeInvalidOperations.ts (45 errors) ====
// ++ operator on any type
var ANY1;
var ANY1: any;
var ANY2: any[] = [1, 2];
var obj: () => {}
@@ -58,7 +58,7 @@ tests/cases/conformance/expressions/unaryOperators/incrementOperator/incrementOp
}
class A {
public a: any;
static foo() {
static foo(): any {
var a;
return a;
}

View File

@@ -1,6 +1,6 @@
//// [incrementOperatorWithAnyOtherTypeInvalidOperations.ts]
// ++ operator on any type
var ANY1;
var ANY1: any;
var ANY2: any[] = [1, 2];
var obj: () => {}
@@ -11,7 +11,7 @@ function foo(): any {
}
class A {
public a: any;
static foo() {
static foo(): any {
var a;
return a;
}

View File

@@ -10,15 +10,15 @@ if (true) {
>x0 : any
var obj1 = { x0: x0 };
>obj1 : { x0: any; }
>{ x0: x0 } : { x0: any; }
>x0 : any
>x0 : any
>obj1 : { x0: undefined; }
>{ x0: x0 } : { x0: undefined; }
>x0 : undefined
>x0 : undefined
var obj2 = { x0 };
>obj2 : { x0: any; }
>{ x0 } : { x0: any; }
>x0 : any
>obj2 : { x0: undefined; }
>{ x0 } : { x0: undefined; }
>x0 : undefined
}
var x, y, z;

View File

@@ -1,7 +1,7 @@
=== tests/cases/compiler/json.stringify.ts ===
var value = null;
>value : null
>value : any
>null : null
JSON.stringify(value, undefined, 2);

View File

@@ -5,7 +5,7 @@ tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperator
// - operator on any type
var ANY: any;
var ANY1;
var ANY1: any;
var ANY2: any[] = ["", ""];
var obj: () => {}
var obj1 = { x: "", y: () => { }};
@@ -16,7 +16,7 @@ tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperator
}
class A {
public a: any;
static foo() {
static foo(): any {
var a;
return a;
}

View File

@@ -2,7 +2,7 @@
// - operator on any type
var ANY: any;
var ANY1;
var ANY1: any;
var ANY2: any[] = ["", ""];
var obj: () => {}
var obj1 = { x: "", y: () => { }};
@@ -13,7 +13,7 @@ function foo(): any {
}
class A {
public a: any;
static foo() {
static foo(): any {
var a;
return a;
}

View File

@@ -31,7 +31,7 @@ function a1() {
for (let x; x < 1;) {
>x : any
>x < 1 : boolean
>x : any
>x : undefined
>1 : 1
() => x;
@@ -53,24 +53,24 @@ function a2() {
for (let x; x < 1;) {
>x : any
>x < 1 : boolean
>x : any
>x : number
>1 : 1
x = x + 1;
>x = x + 1 : any
>x : any
>x + 1 : any
>x = x + 1 : number
>x : any
>x + 1 : number
>x : number
>1 : 1
}
for (let x;;) {
>x : any
x = x + 2;
>x = x + 2 : any
>x : any
>x + 2 : any
>x = x + 2 : number
>x : any
>x + 2 : number
>x : number
>2 : 2
}
}
@@ -82,14 +82,14 @@ function a3() {
for (let x; x < 1;) {
>x : any
>x < 1 : boolean
>x : any
>x : number
>1 : 1
x = x + 1;
>x = x + 1 : any
>x : any
>x + 1 : any
>x = x + 1 : number
>x : any
>x + 1 : number
>x : number
>1 : 1
}
switch (1) {
@@ -111,14 +111,14 @@ function a4() {
for (let x; x < 1;) {
>x : any
>x < 1 : boolean
>x : any
>x : number
>1 : 1
x = x + 1;
>x = x + 1 : any
>x : any
>x + 1 : any
>x = x + 1 : number
>x : any
>x + 1 : number
>x : number
>1 : 1
() => x;
@@ -145,14 +145,14 @@ function a5() {
for (let x; x < 1;) {
>x : any
>x < 1 : boolean
>x : any
>x : number
>1 : 1
x = x + 1;
>x = x + 1 : any
>x : any
>x + 1 : any
>x = x + 1 : number
>x : any
>x + 1 : number
>x : number
>1 : 1
() => x;

View File

@@ -5,24 +5,24 @@ function a0() {
for (let x; x < 1;) {
>x : any
>x < 1 : boolean
>x : any
>x : number
>1 : 1
x = x + 1;
>x = x + 1 : any
>x : any
>x + 1 : any
>x = x + 1 : number
>x : any
>x + 1 : number
>x : number
>1 : 1
}
for (let x;;) {
>x : any
x = x + 2;
>x = x + 2 : any
>x : any
>x + 2 : any
>x = x + 2 : number
>x : any
>x + 2 : number
>x : number
>2 : 2
}
}
@@ -33,14 +33,14 @@ function a1() {
for (let x; x < 1;) {
>x : any
>x < 1 : boolean
>x : any
>x : number
>1 : 1
x = x + 1;
>x = x + 1 : any
>x : any
>x + 1 : any
>x = x + 1 : number
>x : any
>x + 1 : number
>x : number
>1 : 1
() => x;
@@ -51,10 +51,10 @@ function a1() {
>x : any
x = x + 2;
>x = x + 2 : any
>x : any
>x + 2 : any
>x = x + 2 : number
>x : any
>x + 2 : number
>x : number
>2 : 2
}
}
@@ -65,24 +65,24 @@ function a2() {
for (let x; x < 1;) {
>x : any
>x < 1 : boolean
>x : any
>x : number
>1 : 1
x = x + 1;
>x = x + 1 : any
>x : any
>x + 1 : any
>x = x + 1 : number
>x : any
>x + 1 : number
>x : number
>1 : 1
}
for (let x;;) {
>x : any
x = x + 2;
>x = x + 2 : any
>x : any
>x + 2 : any
>x = x + 2 : number
>x : any
>x + 2 : number
>x : number
>2 : 2
() => x;
@@ -98,14 +98,14 @@ function a3() {
for (let x; x < 1;) {
>x : any
>x < 1 : boolean
>x : any
>x : number
>1 : 1
x = x + 1;
>x = x + 1 : any
>x : any
>x + 1 : any
>x = x + 1 : number
>x : any
>x + 1 : number
>x : number
>1 : 1
() => x;
@@ -116,10 +116,10 @@ function a3() {
>x : any
x = x + 2;
>x = x + 2 : any
>x : any
>x + 2 : any
>x = x + 2 : number
>x : any
>x + 2 : number
>x : number
>2 : 2
() => x;

View File

@@ -18,10 +18,10 @@ function a0() {
>x : any
x = x + 2;
>x = x + 2 : any
>x : any
>x + 2 : any
>x = x + 2 : number
>x : any
>x + 2 : number
>x : number
>2 : 2
}
}
@@ -49,10 +49,10 @@ function a1() {
>x : any
x = x + 2;
>x = x + 2 : any
>x : any
>x + 2 : any
>x = x + 2 : number
>x : any
>x + 2 : number
>x : number
>2 : 2
}
}
@@ -76,10 +76,10 @@ function a2() {
>x : any
x = x + 2;
>x = x + 2 : any
>x : any
>x + 2 : any
>x = x + 2 : number
>x : any
>x + 2 : number
>x : number
>2 : 2
() => x;
@@ -111,10 +111,10 @@ function a3() {
>x : any
x = x + 2;
>x = x + 2 : any
>x : any
>x + 2 : any
>x = x + 2 : number
>x : any
>x + 2 : number
>x : number
>2 : 2
() => x;

View File

@@ -2,14 +2,10 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,5): error TS1
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,6): error TS7031: Binding element 'a' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,10): error TS1182: A destructuring declaration must have an initializer.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,11): error TS7031: Binding element 'b' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,15): error TS7005: Variable 'c' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(1,18): error TS7005: Variable 'd' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,5): error TS1182: A destructuring declaration must have an initializer.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,6): error TS7031: Binding element 'a1' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,23): error TS1182: A destructuring declaration must have an initializer.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,24): error TS7031: Binding element 'b1' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,36): error TS7005: Variable 'c1' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(3,52): error TS7005: Variable 'd1' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(5,5): error TS1182: A destructuring declaration must have an initializer.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(5,18): error TS1182: A destructuring declaration must have an initializer.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,5): error TS1182: A destructuring declaration must have an initializer.
@@ -17,12 +13,10 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,13): error TS
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(7,25): error TS7008: Member 'b3' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,6): error TS7031: Binding element 'a4' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,26): error TS7031: Binding element 'b4' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,46): error TS7005: Variable 'c4' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,62): error TS7005: Variable 'd4' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS7031: Binding element 'a5' implicitly has an 'any' type.
==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (22 errors) ====
==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (16 errors) ====
var [a], {b}, c, d; // error
~~~
!!! error TS1182: A destructuring declaration must have an initializer.
@@ -32,10 +26,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS
!!! error TS1182: A destructuring declaration must have an initializer.
~
!!! error TS7031: Binding element 'b' implicitly has an 'any' type.
~
!!! error TS7005: Variable 'c' implicitly has an 'any' type.
~
!!! error TS7005: Variable 'd' implicitly has an 'any' type.
var [a1 = undefined], {b1 = null}, c1 = undefined, d1 = null; // error
~~~~~~~~~~~~~~~~
@@ -46,10 +36,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS
!!! error TS1182: A destructuring declaration must have an initializer.
~~
!!! error TS7031: Binding element 'b1' implicitly has an 'any' type.
~~
!!! error TS7005: Variable 'c1' implicitly has an 'any' type.
~~
!!! error TS7005: Variable 'd1' implicitly has an 'any' type.
var [a2]: [any], {b2}: { b2: any }, c2: any, d2: any;
~~~~
@@ -70,10 +56,6 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS
!!! error TS7031: Binding element 'a4' implicitly has an 'any' type.
~~
!!! error TS7031: Binding element 'b4' implicitly has an 'any' type.
~~
!!! error TS7005: Variable 'c4' implicitly has an 'any' type.
~~
!!! error TS7005: Variable 'd4' implicitly has an 'any' type.
var [a5 = undefined] = []; // error
~~

View File

@@ -1,11 +1,10 @@
tests/cases/compiler/noImplicitAnyForIn.ts(8,18): error TS7017: Index signature of object type implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyForIn.ts(15,18): error TS7017: Index signature of object type implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyForIn.ts(21,9): error TS7005: Variable 'b' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyForIn.ts(29,5): error TS7005: Variable 'n' implicitly has an 'any[][]' type.
tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'.
==== tests/cases/compiler/noImplicitAnyForIn.ts (5 errors) ====
==== tests/cases/compiler/noImplicitAnyForIn.ts (4 errors) ====
var x: {}[] = [[1, 2, 3], ["hello"]];
@@ -31,8 +30,6 @@ tests/cases/compiler/noImplicitAnyForIn.ts(31,6): error TS2405: The left-hand si
for (var a in x) {
// Should yield an implicit 'any' error.
var b;
~
!!! error TS7005: Variable 'b' implicitly has an 'any' type.
var c = a || b;
}

View File

@@ -5,10 +5,10 @@ var x=null;
>null : null
var y=3+x;
>y : any
>3+x : any
>y : number
>3+x : number
>3 : 3
>x : any
>x : null
var z=3+null;
>z : number

View File

@@ -5,35 +5,35 @@ var a, b, c;
>c : any
var x1 = {
>x1 : { a: any; }
>{ a} : { a: any; }
>x1 : { a: undefined; }
>{ a} : { a: undefined; }
a
>a : any
>a : undefined
};
var x2 = {
>x2 : { a: any; }
>{ a,} : { a: any; }
>x2 : { a: undefined; }
>{ a,} : { a: undefined; }
a,
>a : any
>a : undefined
}
var x3 = {
>x3 : any
>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; }
>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: undefined; c: undefined; d(): void; x3: any; parent: any; }
a: 0,
>a : number
>0 : 0
b,
>b : any
>b : undefined
c,
>c : any
>c : undefined
d() { },
>d : () => void

View File

@@ -5,35 +5,35 @@ var a, b, c;
>c : any
var x1 = {
>x1 : { a: any; }
>{ a} : { a: any; }
>x1 : { a: undefined; }
>{ a} : { a: undefined; }
a
>a : any
>a : undefined
};
var x2 = {
>x2 : { a: any; }
>{ a,} : { a: any; }
>x2 : { a: undefined; }
>{ a,} : { a: undefined; }
a,
>a : any
>a : undefined
}
var x3 = {
>x3 : any
>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: any; c: any; d(): void; x3: any; parent: any; }
>{ a: 0, b, c, d() { }, x3, parent: x3} : { a: number; b: undefined; c: undefined; d(): void; x3: any; parent: any; }
a: 0,
>a : number
>0 : 0
b,
>b : any
>b : undefined
c,
>c : any
>c : undefined
d() { },
>d : () => void

View File

@@ -10,12 +10,12 @@ function f1() {
if (a < b || b > (c + 1)) { }
>a < b || b > (c + 1) : boolean
>a < b : boolean
>a : any
>b : any
>a : undefined
>b : undefined
>b > (c + 1) : boolean
>b : any
>(c + 1) : any
>c + 1 : any
>c : any
>b : undefined
>(c + 1) : number
>c + 1 : number
>c : undefined
>1 : 1
}

View File

@@ -10,12 +10,12 @@ function f() {
if (a < b && b > (c + 1)) { }
>a < b && b > (c + 1) : boolean
>a < b : boolean
>a : any
>b : any
>a : undefined
>b : undefined
>b > (c + 1) : boolean
>b : any
>(c + 1) : any
>c + 1 : any
>c : any
>b : undefined
>(c + 1) : number
>c + 1 : number
>c : undefined
>1 : 1
}

View File

@@ -10,13 +10,13 @@ function f() {
if (a < b && b < (c + 1)) { }
>a < b && b < (c + 1) : boolean
>a < b : boolean
>a : any
>b : any
>a : undefined
>b : undefined
>b < (c + 1) : boolean
>b : any
>(c + 1) : any
>c + 1 : any
>c : any
>b : undefined
>(c + 1) : number
>c + 1 : number
>c : undefined
>1 : 1
}

View File

@@ -25,6 +25,9 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(776,42): e
tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(781,23): error TS2503: Cannot find namespace 'TypeScript'.
tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(794,49): error TS2304: Cannot find name 'TypeScript'.
tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(795,49): error TS2304: Cannot find name 'TypeScript'.
tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(820,31): error TS2339: Property 'length' does not exist on type 'null'.
tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(976,28): error TS2339: Property 'length' does not exist on type 'null'.
tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(977,82): error TS2339: Property 'join' does not exist on type 'null'.
tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,53): error TS2304: Cannot find name 'TypeScript'.
tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,89): error TS2304: Cannot find name 'TypeScript'.
tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(987,115): error TS2503: Cannot find namespace 'TypeScript'.
@@ -110,7 +113,7 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(1787,68):
tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32): error TS2304: Cannot find name 'Diff'.
==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (110 errors) ====
==== tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts (113 errors) ====
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
@@ -985,6 +988,8 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32):
})
return errors.length === 0;
~~~~~~
!!! error TS2339: Property 'length' does not exist on type 'null'.
}
public isSubtypeOf(other: Type) {
@@ -1141,7 +1146,11 @@ tests/cases/conformance/parser/ecmascript5/RealWorld/parserharness.ts(2030,32):
})
if (errors.length > 0)
~~~~~~
!!! error TS2339: Property 'length' does not exist on type 'null'.
throw new Error("Type definition contains errors: " + errors.join(","));
~~~~
!!! error TS2339: Property 'join' does not exist on type 'null'.
var matchingIdentifiers: Type[] = [];

View File

@@ -14,11 +14,11 @@ var WorkspacePrototype = {
}
};
WorkspacePrototype['__proto__'] = EntityPrototype;
>WorkspacePrototype['__proto__'] = EntityPrototype : any
>WorkspacePrototype['__proto__'] = EntityPrototype : undefined
>WorkspacePrototype['__proto__'] : any
>WorkspacePrototype : { serialize: () => any; }
>'__proto__' : "___proto__"
>EntityPrototype : any
>EntityPrototype : undefined
var o = {
>o : { "__proto__": number; }

View File

@@ -1,11 +1,11 @@
=== tests/cases/conformance/types/typeRelationships/widenedTypes/strictNullChecksNoWidening.ts ===
var a1 = null;
>a1 : null
>a1 : any
>null : null
var a2 = undefined;
>a2 : undefined
>a2 : any
>undefined : undefined
var a3 = void 0;

View File

@@ -61,7 +61,7 @@ var selfClosed7 = <div x={p} y='p' />;
><div x={p} y='p' /> : JSX.Element
>div : any
>x : any
>p : any
>p : undefined
>y : any
var openClosed1 = <div></div>;
@@ -82,7 +82,7 @@ var openClosed3 = <div n='m'>{p}</div>;
><div n='m'>{p}</div> : JSX.Element
>div : any
>n : any
>p : any
>p : undefined
>div : any
var openClosed4 = <div n='m'>{p < p}</div>;
@@ -91,8 +91,8 @@ var openClosed4 = <div n='m'>{p < p}</div>;
>div : any
>n : any
>p < p : boolean
>p : any
>p : any
>p : undefined
>p : undefined
>div : any
var openClosed5 = <div n='m'>{p > p}</div>;
@@ -101,8 +101,8 @@ var openClosed5 = <div n='m'>{p > p}</div>;
>div : any
>n : any
>p > p : boolean
>p : any
>p : any
>p : undefined
>p : undefined
>div : any
class SomeClass {
@@ -180,7 +180,7 @@ var whitespace2 = <div> {p} </div>;
>whitespace2 : JSX.Element
><div> {p} </div> : JSX.Element
>div : any
>p : any
>p : undefined
>div : any
var whitespace3 = <div>
@@ -189,7 +189,7 @@ var whitespace3 = <div>
>div : any
{p}
>p : any
>p : undefined
</div>;
>div : any

View File

@@ -22,16 +22,16 @@ var spreads1 = <div {...p1}>{p2}</div>;
>spreads1 : JSX.Element
><div {...p1}>{p2}</div> : JSX.Element
>div : any
>p1 : any
>p2 : any
>p1 : undefined
>p2 : undefined
>div : any
var spreads2 = <div {...p1}>{p2}</div>;
>spreads2 : JSX.Element
><div {...p1}>{p2}</div> : JSX.Element
>div : any
>p1 : any
>p2 : any
>p1 : undefined
>p2 : undefined
>div : any
var spreads3 = <div x={p3} {...p1}>{p2}</div>;
@@ -39,19 +39,19 @@ var spreads3 = <div x={p3} {...p1}>{p2}</div>;
><div x={p3} {...p1}>{p2}</div> : JSX.Element
>div : any
>x : any
>p3 : any
>p1 : any
>p2 : any
>p3 : undefined
>p1 : undefined
>p2 : undefined
>div : any
var spreads4 = <div {...p1} x={p3} >{p2}</div>;
>spreads4 : JSX.Element
><div {...p1} x={p3} >{p2}</div> : JSX.Element
>div : any
>p1 : any
>p1 : undefined
>x : any
>p3 : any
>p2 : any
>p3 : undefined
>p2 : undefined
>div : any
var spreads5 = <div x={p2} {...p1} y={p3}>{p2}</div>;
@@ -59,10 +59,10 @@ var spreads5 = <div x={p2} {...p1} y={p3}>{p2}</div>;
><div x={p2} {...p1} y={p3}>{p2}</div> : JSX.Element
>div : any
>x : any
>p2 : any
>p1 : any
>p2 : undefined
>p1 : undefined
>y : any
>p3 : any
>p2 : any
>p3 : undefined
>p2 : undefined
>div : any

View File

@@ -3,7 +3,7 @@ declare module JSX {
interface Element { isElement; }
}
var T, T1, T2;
var T: any, T1: any, T2: any;
// This is an element
var x1 = <T>() => {}</T>;

View File

@@ -7,10 +7,10 @@ declare module JSX {
>isElement : Symbol(Element.isElement, Decl(file.tsx, 1, 20))
}
var T, T1, T2;
var T: any, T1: any, T2: any;
>T : Symbol(T, Decl(file.tsx, 4, 3))
>T1 : Symbol(T1, Decl(file.tsx, 4, 6))
>T2 : Symbol(T2, Decl(file.tsx, 4, 10))
>T1 : Symbol(T1, Decl(file.tsx, 4, 11))
>T2 : Symbol(T2, Decl(file.tsx, 4, 20))
// This is an element
var x1 = <T>() => {}</T>;

View File

@@ -7,7 +7,7 @@ declare module JSX {
>isElement : any
}
var T, T1, T2;
var T: any, T1: any, T2: any;
>T : any
>T1 : any
>T2 : any

View File

@@ -63,7 +63,7 @@ var selfClosed7 = <div x={p} y='p' b />;
><div x={p} y='p' b /> : JSX.Element
>div : any
>x : any
>p : any
>p : undefined
>y : any
>b : any
@@ -85,7 +85,7 @@ var openClosed3 = <div n='m'>{p}</div>;
><div n='m'>{p}</div> : JSX.Element
>div : any
>n : any
>p : any
>p : undefined
>div : any
var openClosed4 = <div n='m'>{p < p}</div>;
@@ -94,8 +94,8 @@ var openClosed4 = <div n='m'>{p < p}</div>;
>div : any
>n : any
>p < p : boolean
>p : any
>p : any
>p : undefined
>p : undefined
>div : any
var openClosed5 = <div n='m' b>{p > p}</div>;
@@ -105,8 +105,8 @@ var openClosed5 = <div n='m' b>{p > p}</div>;
>n : any
>b : any
>p > p : boolean
>p : any
>p : any
>p : undefined
>p : undefined
>div : any
class SomeClass {
@@ -184,7 +184,7 @@ var whitespace2 = <div> {p} </div>;
>whitespace2 : JSX.Element
><div> {p} </div> : JSX.Element
>div : any
>p : any
>p : undefined
>div : any
var whitespace3 = <div>
@@ -193,7 +193,7 @@ var whitespace3 = <div>
>div : any
{p}
>p : any
>p : undefined
</div>;
>div : any

View File

@@ -24,16 +24,16 @@ var spreads1 = <div {...p1}>{p2}</div>;
>spreads1 : JSX.Element
><div {...p1}>{p2}</div> : JSX.Element
>div : any
>p1 : any
>p2 : any
>p1 : undefined
>p2 : undefined
>div : any
var spreads2 = <div {...p1}>{p2}</div>;
>spreads2 : JSX.Element
><div {...p1}>{p2}</div> : JSX.Element
>div : any
>p1 : any
>p2 : any
>p1 : undefined
>p2 : undefined
>div : any
var spreads3 = <div x={p3} {...p1}>{p2}</div>;
@@ -41,19 +41,19 @@ var spreads3 = <div x={p3} {...p1}>{p2}</div>;
><div x={p3} {...p1}>{p2}</div> : JSX.Element
>div : any
>x : any
>p3 : any
>p1 : any
>p2 : any
>p3 : undefined
>p1 : undefined
>p2 : undefined
>div : any
var spreads4 = <div {...p1} x={p3} >{p2}</div>;
>spreads4 : JSX.Element
><div {...p1} x={p3} >{p2}</div> : JSX.Element
>div : any
>p1 : any
>p1 : undefined
>x : any
>p3 : any
>p2 : any
>p3 : undefined
>p2 : undefined
>div : any
var spreads5 = <div x={p2} {...p1} y={p3}>{p2}</div>;
@@ -61,10 +61,10 @@ var spreads5 = <div x={p2} {...p1} y={p3}>{p2}</div>;
><div x={p2} {...p1} y={p3}>{p2}</div> : JSX.Element
>div : any
>x : any
>p2 : any
>p1 : any
>p2 : undefined
>p1 : undefined
>y : any
>p3 : any
>p2 : any
>p3 : undefined
>p2 : undefined
>div : any

View File

@@ -32,6 +32,6 @@ var spread1 = <div x='' {...foo} y='' />;
><div x='' {...foo} y='' /> : JSX.Element
>div : any
>x : any
>foo : any
>foo : undefined
>y : any

View File

@@ -35,7 +35,7 @@ namespace M {
><div x='' {...foo} y='' /> : JSX.Element
>div : any
>x : any
>foo : any
>foo : undefined
>y : any
// Quotes

View File

@@ -0,0 +1,15 @@
tests/cases/compiler/file1.ts(3,12): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
==== tests/cases/compiler/file2.ts (0 errors) ====
import f = require('./file1');
f.foo();
==== tests/cases/compiler/file1.ts (1 errors) ====
export function foo() {
var classes = undefined;
return new classes(null);
~~~~~~~~~~~~~~~~~
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
}

View File

@@ -4,9 +4,10 @@ tests/cases/compiler/unusedSwitchStatment.ts(7,15): error TS6133: 'c' is declare
tests/cases/compiler/unusedSwitchStatment.ts(10,13): error TS6133: 'z' is declared but never used.
tests/cases/compiler/unusedSwitchStatment.ts(15,10): error TS2678: Type '0' is not comparable to type '2'.
tests/cases/compiler/unusedSwitchStatment.ts(17,10): error TS2678: Type '1' is not comparable to type '2'.
tests/cases/compiler/unusedSwitchStatment.ts(18,9): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
==== tests/cases/compiler/unusedSwitchStatment.ts (6 errors) ====
==== tests/cases/compiler/unusedSwitchStatment.ts (7 errors) ====
switch (1) {
case 0:
@@ -37,4 +38,6 @@ tests/cases/compiler/unusedSwitchStatment.ts(17,10): error TS2678: Type '1' is n
~
!!! error TS2678: Type '1' is not comparable to type '2'.
x++;
~
!!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type.
}

View File

@@ -1,3 +1,3 @@
var x;
var x: any;
x.name = "hello";
var z = x + x;

View File

@@ -0,0 +1,129 @@
// @strictNullChecks: true
declare let cond: boolean;
// CFA for 'let' with no type annotation and initializer
function f1() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'undefined' initializer
function f2() {
let x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'null' initializer
function f3() {
let x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | null
}
// No CFA for 'let' with with type annotation
function f4() {
let x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// CFA for 'var' with no type annotation and initializer
function f5() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'undefined' initializer
function f6() {
var x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'null' initializer
function f7() {
var x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | null
}
// No CFA for 'var' with with type annotation
function f8() {
var x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// No CFA for captured outer variables
function f9() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
function f() {
const z = x; // any
}
}
// No CFA for captured outer variables
function f10() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
const f = () => {
const z = x; // any
};
}

View File

@@ -0,0 +1,130 @@
// @strictNullChecks: true
// @noImplicitAny: true
declare let cond: boolean;
// CFA for 'let' with no type annotation and initializer
function f1() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'undefined' initializer
function f2() {
let x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'let' with no type annotation and 'null' initializer
function f3() {
let x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | null
}
// No CFA for 'let' with with type annotation
function f4() {
let x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// CFA for 'var' with no type annotation and initializer
function f5() {
var x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'undefined' initializer
function f6() {
var x = undefined;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
}
// CFA for 'var' with no type annotation and 'null' initializer
function f7() {
var x = null;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | null
}
// No CFA for 'var' with with type annotation
function f8() {
var x: any;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // any
}
// No CFA for captured outer variables
function f9() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
function f() {
const z = x; // any
}
}
// No CFA for captured outer variables
function f10() {
let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x; // string | number | undefined
const f = () => {
const z = x; // any
};
}

View File

@@ -1,10 +1,10 @@
// @lib: es5,es2015.promise
// @noEmitHelpers: true
// @target: ES5
declare var x, y, z, a, b, c;
declare var x: any, y: any, z: any, a: any, b: any, c: any;
async function tryCatch0() {
var x, y;
var x: any, y: any;
try {
x;
}
@@ -14,7 +14,7 @@ async function tryCatch0() {
}
async function tryCatch1() {
var x, y;
var x: any, y: any;
try {
await x;
}
@@ -24,7 +24,7 @@ async function tryCatch1() {
}
async function tryCatch2() {
var x, y;
var x: any, y: any;
try {
x;
}
@@ -34,7 +34,7 @@ async function tryCatch2() {
}
async function tryCatch3(): Promise<Function> {
var x, y;
var x: any, y: any;
try {
await x;
}
@@ -43,7 +43,7 @@ async function tryCatch3(): Promise<Function> {
}
}
async function tryFinally0() {
var x, y;
var x: any, y: any;
try {
x;
}
@@ -53,7 +53,7 @@ async function tryFinally0() {
}
async function tryFinally1() {
var x, y;
var x: any, y: any;
try {
await x;
}
@@ -63,7 +63,7 @@ async function tryFinally1() {
}
async function tryFinally2() {
var x, y;
var x: any, y: any;
try {
x;
}
@@ -73,7 +73,7 @@ async function tryFinally2() {
}
async function tryCatchFinally0() {
var x, y, z;
var x: any, y: any, z: any;
try {
x;
}
@@ -86,7 +86,7 @@ async function tryCatchFinally0() {
}
async function tryCatchFinally1() {
var x, y, z;
var x: any, y: any, z: any;
try {
await x;
}
@@ -99,7 +99,7 @@ async function tryCatchFinally1() {
}
async function tryCatchFinally2() {
var x, y, z;
var x: any, y: any, z: any;
try {
x;
}
@@ -112,7 +112,7 @@ async function tryCatchFinally2() {
}
async function tryCatchFinally3() {
var x, y, z;
var x: any, y: any, z: any;
try {
x;
}

View File

@@ -6,7 +6,7 @@ enum E {
}
function f() {
var a;
var a: any;
var n=3;
var s="";
var b=false;

View File

@@ -1,8 +1,9 @@
// @noimplicitany: true
// this should be an error
var x; // error at "x"
declare var foo; // error at "foo"
function func(k) { }; //error at "k"
var x; // no error, control flow typed
var y; // error because captured
declare var foo; // error at "foo"
function func(k) { y }; // error at "k"
func(x);
// this shouldn't be an error

View File

@@ -1,6 +1,6 @@
//@target: ES5
module M {
var Symbol;
var Symbol: any;
export class C {
[Symbol.iterator]() { }

View File

@@ -1,5 +1,5 @@
//@target: ES5
var Symbol;
var Symbol: any;
class C {
[Symbol.iterator]() { }

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