diff --git a/README.md b/README.md index d21e558360c..053d036411e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Build Status](https://travis-ci.org/Microsoft/TypeScript.svg?branch=master)](https://travis-ci.org/Microsoft/TypeScript) [![npm version](https://badge.fury.io/js/typescript.svg)](https://www.npmjs.com/package/typescript) -[![Downloads](https://img.shields.io/npm/dm/TypeScript.svg)](https://www.npmjs.com/package/typescript) +[![Downloads](https://img.shields.io/npm/dm/typescript.svg)](https://www.npmjs.com/package/typescript) # TypeScript diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b2ad2151bb6..27b3067278c 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1414,6 +1414,7 @@ namespace ts { if (isObjectLiteralOrClassExpressionMethod(node)) { return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike | ContainerFlags.IsObjectLiteralOrClassExpressionMethod; } + // falls through case SyntaxKind.Constructor: case SyntaxKind.FunctionDeclaration: case SyntaxKind.MethodSignature: @@ -1715,7 +1716,7 @@ namespace ts { declareModuleMember(node, symbolFlags, symbolExcludes); break; } - // fall through. + // falls through default: if (!blockScopeContainer.locals) { blockScopeContainer.locals = createMap(); @@ -2009,6 +2010,7 @@ namespace ts { bindBlockScopedDeclaration(parentNode, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); break; } + // falls through case SyntaxKind.ThisKeyword: if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) { node.flowNode = currentFlow; @@ -2184,7 +2186,7 @@ namespace ts { if (!isFunctionLike(node.parent)) { return; } - // Fall through + // falls through case SyntaxKind.ModuleBlock: return updateStrictModeStatementList((node).statements); } @@ -2401,7 +2403,7 @@ namespace ts { } function lookupSymbolForName(name: string) { - return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || container.locals.get(name); + return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || (container.locals && container.locals.get(name)); } function bindPropertyAssignment(functionName: string, propertyAccessExpression: PropertyAccessExpression, isPrototypeProperty: boolean) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 37de59ce195..0447e42ed64 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -349,7 +349,7 @@ namespace ts { TypeofNEHostObject = 1 << 13, // typeof x !== "xxx" EQUndefined = 1 << 14, // x === undefined EQNull = 1 << 15, // x === null - EQUndefinedOrNull = 1 << 16, // x == undefined / x == null + EQUndefinedOrNull = 1 << 16, // x === undefined / x === null NEUndefined = 1 << 17, // x !== undefined NENull = 1 << 18, // x !== null NEUndefinedOrNull = 1 << 19, // x != undefined / x != null @@ -727,7 +727,7 @@ namespace ts { if (declarationFile !== useFile) { if ((modulekind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) || (!compilerOptions.outFile && !compilerOptions.out)) { - // nodes are in different files and order cannot be determines + // nodes are in different files and order cannot be determined return true; } // declaration is after usage @@ -745,7 +745,7 @@ namespace ts { // still might be illegal if declaration and usage are both binding elements (eg var [a = b, b = b] = [1, 2]) const errorBindingElement = getAncestor(usage, SyntaxKind.BindingElement) as BindingElement; if (errorBindingElement) { - return getAncestorBindingPattern(errorBindingElement) !== getAncestorBindingPattern(declaration) || + return findAncestor(errorBindingElement, isBindingElement) !== findAncestor(declaration, isBindingElement) || declaration.pos < errorBindingElement.pos; } // or it might be illegal if usage happens before parent variable is declared (eg var [a] = a) @@ -760,11 +760,19 @@ namespace ts { // declaration is after usage, but it can still be legal if usage is deferred: - // 1. inside a function - // 2. inside an instance property initializer, a reference to a non-instance property - // 3. inside a static property initializer, a reference to a static method in the same class + // 1. inside an export specifier + // 2. inside a function + // 3. inside an instance property initializer, a reference to a non-instance property + // 4. inside a static property initializer, a reference to a static method in the same class + // or if usage is in a type context: + // 1. inside a type query (typeof in type position) + if (usage.parent.kind === SyntaxKind.ExportSpecifier) { + // export specifiers do not use the variable, they only make it available for use + return true; + } + const container = getEnclosingBlockScopeContainer(declaration); - return isUsedInFunctionOrInstanceProperty(usage, declaration, container); + return isInTypeQuery(usage) || isUsedInFunctionOrInstanceProperty(usage, declaration, container); function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration: VariableDeclaration, usage: Node): boolean { const container = getEnclosingBlockScopeContainer(declaration); @@ -794,12 +802,10 @@ namespace ts { } function isUsedInFunctionOrInstanceProperty(usage: Node, declaration: Node, container?: Node): boolean { - let current = usage; - while (current) { + return !!findAncestor(usage, current => { if (current === container) { - return false; + return "quit"; } - if (isFunctionLike(current)) { return true; } @@ -821,20 +827,7 @@ namespace ts { } } } - - current = current.parent; - } - return false; - } - - function getAncestorBindingPattern(node: Node): BindingPattern { - while (node) { - if (isBindingPattern(node)) { - return node; - } - node = node.parent; - } - return undefined; + }); } } @@ -896,6 +889,7 @@ namespace ts { case SyntaxKind.SourceFile: if (!isExternalOrCommonJsModule(location)) break; isInExternalModule = true; + // falls through case SyntaxKind.ModuleDeclaration: const moduleExports = getSymbolOfNode(location).exports; if (location.kind === SyntaxKind.SourceFile || isAmbientModule(location)) { @@ -1256,15 +1250,7 @@ namespace ts { * Return false if 'stopAt' node is reached or isFunctionLike(current) === true. */ function isSameScopeDescendentOf(initial: Node, parent: Node, stopAt: Node): boolean { - if (!parent) { - return false; - } - for (let current = initial; current && current !== stopAt && !isFunctionLike(current); current = current.parent) { - if (current === parent) { - return true; - } - } - return false; + return parent && !!findAncestor(initial, n => n === stopAt || isFunctionLike(n) ? "quit" : n === parent); } function getAnyImportSyntax(node: Node): AnyImportSyntax { @@ -1273,10 +1259,7 @@ namespace ts { return node; } - while (node && node.kind !== SyntaxKind.ImportDeclaration) { - node = node.parent; - } - return node; + return findAncestor(node, n => n.kind === SyntaxKind.ImportDeclaration) as ImportDeclaration; } } @@ -1932,6 +1915,7 @@ namespace ts { if (!isExternalOrCommonJsModule(location)) { break; } + // falls through case SyntaxKind.ModuleDeclaration: if (result = callback(getSymbolOfNode(location).exports)) { return result; @@ -2137,11 +2121,8 @@ namespace ts { return { accessibility: SymbolAccessibility.Accessible }; function getExternalModuleContainer(declaration: Node) { - for (; declaration; declaration = declaration.parent) { - if (hasExternalModuleSymbol(declaration)) { - return getSymbolOfNode(declaration); - } - } + const node = findAncestor(declaration, hasExternalModuleSymbol); + return node && getSymbolOfNode(node); } } @@ -2885,10 +2866,7 @@ namespace ts { function getTypeAliasForTypeLiteral(type: Type): Symbol { if (type.symbol && type.symbol.flags & SymbolFlags.TypeLiteral) { - let node = type.symbol.declarations[0].parent; - while (node.kind === SyntaxKind.ParenthesizedType) { - node = node.parent; - } + const node = findAncestor(type.symbol.declarations[0].parent, n => n.kind !== SyntaxKind.ParenthesizedType); if (node.kind === SyntaxKind.TypeAliasDeclaration) { return getSymbolOfNode(node); } @@ -3652,7 +3630,7 @@ namespace ts { // If the binding pattern is empty, this variable declaration is not visible return false; } - // Otherwise fall through + // falls through case SyntaxKind.ModuleDeclaration: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: @@ -3683,7 +3661,8 @@ namespace ts { // Private/protected properties/methods are not visible return false; } - // Public properties/methods are visible if its parents are visible, so const it fall into next case statement + // Public properties/methods are visible if its parents are visible, so: + // falls through case SyntaxKind.Constructor: case SyntaxKind.ConstructSignature: @@ -3831,8 +3810,7 @@ namespace ts { } function getDeclarationContainer(node: Node): Node { - node = getRootDeclaration(node); - while (node) { + node = findAncestor(getRootDeclaration(node), node => { switch (node.kind) { case SyntaxKind.VariableDeclaration: case SyntaxKind.VariableDeclarationList: @@ -3840,13 +3818,12 @@ namespace ts { case SyntaxKind.NamedImports: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportClause: - node = node.parent; - break; - + return false; default: - return node.parent; + return true; } - } + }); + return node && node.parent; } function getTypeOfPrototypeProperty(prototype: Symbol): Type { @@ -7918,8 +7895,10 @@ namespace ts { // Starting with the parent of the symbol's declaration, check if the mapper maps any of // the type parameters introduced by enclosing declarations. We just pick the first // declaration since multiple declarations will all have the same parent anyway. - let node: Node = symbol.declarations[0]; - while (node) { + return !!findAncestor(symbol.declarations[0], node => { + if (node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.SourceFile) { + return "quit"; + } switch (node.kind) { case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: @@ -7966,13 +7945,8 @@ namespace ts { } } break; - case SyntaxKind.ModuleDeclaration: - case SyntaxKind.SourceFile: - return false; } - node = node.parent; - } - return false; + }); } function isTopLevelTypeAlias(symbol: Symbol) { @@ -8197,7 +8171,8 @@ namespace ts { function isSignatureAssignableTo(source: Signature, target: Signature, ignoreReturnTypes: boolean): boolean { - return compareSignaturesRelated(source, target, ignoreReturnTypes, /*reportErrors*/ false, /*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False; + return compareSignaturesRelated(source, target, /*checkAsCallback*/ false, ignoreReturnTypes, /*reportErrors*/ false, + /*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False; } type ErrorReporter = (message: DiagnosticMessage, arg0?: string, arg1?: string) => void; @@ -8207,6 +8182,7 @@ namespace ts { */ function compareSignaturesRelated(source: Signature, target: Signature, + checkAsCallback: boolean, ignoreReturnTypes: boolean, reportErrors: boolean, errorReporter: ErrorReporter, @@ -8249,9 +8225,23 @@ namespace ts { const sourceParams = source.parameters; const targetParams = target.parameters; for (let i = 0; i < checkCount; i++) { - const s = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source); - const t = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target); - const related = compareTypes(s, t, /*reportErrors*/ false) || compareTypes(t, s, reportErrors); + const sourceType = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source); + const targetType = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target); + const sourceSig = getSingleCallSignature(getNonNullableType(sourceType)); + const targetSig = getSingleCallSignature(getNonNullableType(targetType)); + // In order to ensure that any generic type Foo is at least co-variant with respect to T no matter + // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions, + // they naturally relate only contra-variantly). However, if the source and target parameters both have + // function types with a single call signature, we known we are relating two callback parameters. In + // that case it is sufficient to only relate the parameters of the signatures co-variantly because, + // similar to return values, callback parameters are output positions. This means that a Promise, + // where T is used only in callback parameter positions, will be co-variant (as opposed to bi-variant) + // with respect to T. + const callbacks = sourceSig && targetSig && !sourceSig.typePredicate && !targetSig.typePredicate && + (getFalsyFlags(sourceType) & TypeFlags.Nullable) === (getFalsyFlags(targetType) & TypeFlags.Nullable); + const related = callbacks ? + compareSignaturesRelated(targetSig, sourceSig, /*checkAsCallback*/ true, /*ignoreReturnTypes*/ false, reportErrors, errorReporter, compareTypes) : + !checkAsCallback && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors); if (!related) { if (reportErrors) { errorReporter(Diagnostics.Types_of_parameters_0_and_1_are_incompatible, @@ -8283,7 +8273,11 @@ namespace ts { } } else { - result &= compareTypes(sourceReturnType, targetReturnType, reportErrors); + // When relating callback signatures, we still need to relate return types bi-variantly as otherwise + // the containing type wouldn't be co-variant. For example, interface Foo { add(cb: () => T): void } + // wouldn't be co-variant for T without this rule. + result &= checkAsCallback && compareTypes(targetReturnType, sourceReturnType, /*reportErrors*/ false) || + compareTypes(sourceReturnType, targetReturnType, reportErrors); } } @@ -8714,7 +8708,7 @@ namespace ts { if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) { const isComparingJsxAttributes = !!(source.flags & TypeFlags.JsxAttributes); if ((relation === assignableRelation || relation === comparableRelation) && - (target === globalObjectType || (!isComparingJsxAttributes && isEmptyObjectType(target)))) { + (isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) { return false; } for (const prop of getPropertiesOfObjectType(source)) { @@ -9251,7 +9245,7 @@ namespace ts { * See signatureAssignableTo, compareSignaturesIdentical */ function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): Ternary { - return compareSignaturesRelated(source, target, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo); + return compareSignaturesRelated(source, target, /*checkAsCallback*/ false, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo); } function signaturesIdenticalTo(source: Type, target: Type, kind: SignatureKind): Ternary { @@ -10416,19 +10410,9 @@ namespace ts { // TypeScript 1.0 spec (April 2014): 3.6.3 // A type query consists of the keyword typeof followed by an expression. // The expression is restricted to a single identifier or a sequence of identifiers separated by periods - while (node) { - switch (node.kind) { - case SyntaxKind.TypeQuery: - return true; - case SyntaxKind.Identifier: - case SyntaxKind.QualifiedName: - node = node.parent; - continue; - default: - return false; - } - } - Debug.fail("should not get here"); + return !!findAncestor( + node, + n => n.kind === SyntaxKind.TypeQuery ? true : n.kind === SyntaxKind.Identifier || n.kind === SyntaxKind.QualifiedName ? false : "quit"); } // Return the flow cache key for a "dotted name" (i.e. a sequence of identifiers @@ -10934,7 +10918,7 @@ namespace ts { // we defer subtype reduction until the evolving array type is finalized into a manifest // array type. function addEvolvingArrayElementType(evolvingArrayType: EvolvingArrayType, node: Expression): EvolvingArrayType { - const elementType = getBaseTypeOfLiteralType(getTypeOfExpression(node)); + const elementType = getBaseTypeOfLiteralType(getContextFreeTypeOfExpression(node)); return isTypeSubsetOf(elementType, evolvingArrayType.elementType) ? evolvingArrayType : getEvolvingArrayType(getUnionType([evolvingArrayType.elementType, elementType])); } @@ -11651,15 +11635,11 @@ namespace ts { } function getControlFlowContainer(node: Node): Node { - while (true) { - node = node.parent; - if (isFunctionLike(node) && !getImmediatelyInvokedFunctionExpression(node) || - node.kind === SyntaxKind.ModuleBlock || - node.kind === SyntaxKind.SourceFile || - node.kind === SyntaxKind.PropertyDeclaration) { - return node; - } - } + return findAncestor(node.parent, node => + isFunctionLike(node) && !getImmediatelyInvokedFunctionExpression(node) || + node.kind === SyntaxKind.ModuleBlock || + node.kind === SyntaxKind.SourceFile || + node.kind === SyntaxKind.PropertyDeclaration); } // Check if a parameter is assigned anywhere within its declaring function. @@ -11676,15 +11656,7 @@ namespace ts { } function hasParentWithAssignmentsMarked(node: Node) { - while (true) { - node = node.parent; - if (!node) { - return false; - } - if (isFunctionLike(node) && getNodeLinks(node).flags & NodeCheckFlags.AssignmentsMarked) { - return true; - } - } + return !!findAncestor(node.parent, node => isFunctionLike(node) && !!(getNodeLinks(node).flags & NodeCheckFlags.AssignmentsMarked)); } function markParameterAssignments(node: Node) { @@ -11856,15 +11828,7 @@ namespace ts { } function isInsideFunction(node: Node, threshold: Node): boolean { - let current = node; - while (current && current !== threshold) { - if (isFunctionLike(current)) { - return true; - } - current = current.parent; - } - - return false; + return !!findAncestor(node, n => n === threshold ? "quit" : isFunctionLike(n)); } function checkNestedBlockScopedBinding(node: Identifier, symbol: Symbol): void { @@ -11916,8 +11880,8 @@ namespace ts { } function isAssignedInBodyOfForStatement(node: Identifier, container: ForStatement): boolean { - let current: Node = node; // skip parenthesized nodes + let current: Node = node; while (current.parent.kind === SyntaxKind.ParenthesizedExpression) { current = current.parent; } @@ -11938,15 +11902,7 @@ namespace ts { // at this point we know that node is the target of assignment // now check that modification happens inside the statement part of the ForStatement - while (current !== container) { - if (current === container.statement) { - return true; - } - else { - current = current.parent; - } - } - return false; + return !!findAncestor(current, n => n === container ? "quit" : n === container.statement); } function captureLexicalThis(node: Node, container: Node): void { @@ -12128,12 +12084,7 @@ namespace ts { } function isInConstructorArgumentInitializer(node: Node, constructorDecl: Node): boolean { - for (let n = node; n && n !== constructorDecl; n = n.parent) { - if (n.kind === SyntaxKind.Parameter) { - return true; - } - } - return false; + return !!findAncestor(node, n => n === constructorDecl ? "quit" : n.kind === SyntaxKind.Parameter); } function checkSuperExpression(node: Node): Type { @@ -12159,10 +12110,7 @@ namespace ts { // class B { // [super.foo()]() {} // } - let current = node; - while (current && current !== container && current.kind !== SyntaxKind.ComputedPropertyName) { - current = current.parent; - } + const current = findAncestor(node, n => n === container ? "quit" : n.kind === SyntaxKind.ComputedPropertyName); if (current && current.kind === SyntaxKind.ComputedPropertyName) { error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); } @@ -12766,13 +12714,8 @@ namespace ts { } function getContextualMapper(node: Node) { - while (node) { - if (node.contextualMapper) { - return node.contextualMapper; - } - node = node.parent; - } - return identityMapper; + node = findAncestor(node, n => !!n.contextualMapper); + return node ? node.contextualMapper : identityMapper; } // If the given type is an object or union type, if that type has a single signature, and if @@ -17122,10 +17065,12 @@ namespace ts { return type; } - // Returns the type of an expression. Unlike checkExpression, this function is simply concerned - // with computing the type and may not fully check all contained sub-expressions for errors. - // A cache argument of true indicates that if the function performs a full type check, it is ok - // to cache the result. + /** + * Returns the type of an expression. Unlike checkExpression, this function is simply concerned + * with computing the type and may not fully check all contained sub-expressions for errors. + * A cache argument of true indicates that if the function performs a full type check, it is ok + * to cache the result. + */ function getTypeOfExpression(node: Expression, cache?: boolean) { // Optimize for the common case of a call to a function with a single non-generic call // signature where we can just fetch the return type without checking the arguments. @@ -17142,6 +17087,21 @@ namespace ts { return cache ? checkExpressionCached(node) : checkExpression(node); } + /** + * Returns the type of an expression. Unlike checkExpression, this function is simply concerned + * with computing the type and may not fully check all contained sub-expressions for errors. + * It is intended for uses where you know there is no contextual type, + * and requesting the contextual type might cause a circularity or other bad behaviour. + * It sets the contextual type of the node to any before calling getTypeOfExpression. + */ + function getContextFreeTypeOfExpression(node: Expression) { + const saveContextualType = node.contextualType; + node.contextualType = anyType; + const type = getTypeOfExpression(node); + node.contextualType = saveContextualType; + return type; + } + // Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When // contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the // expression is being inferentially typed (section 4.15.2 in spec) and provides the type mapper to use in @@ -17610,7 +17570,7 @@ namespace ts { function checkObjectTypeForDuplicateDeclarations(node: TypeLiteralNode | InterfaceDeclaration) { const names = createMap(); for (const member of node.members) { - if (member.kind == SyntaxKind.PropertySignature) { + if (member.kind === SyntaxKind.PropertySignature) { let memberName: string; switch (member.name.kind) { case SyntaxKind.StringLiteral: @@ -19011,8 +18971,7 @@ namespace ts { // this function will run after checking the source file so 'CaptureThis' is correct for all nodes function checkIfThisIsCapturedInEnclosingScope(node: Node): void { - let current = node; - while (current) { + findAncestor(node, current => { if (getNodeCheckFlags(current) & NodeCheckFlags.CaptureThis) { const isDeclaration = node.kind !== SyntaxKind.Identifier; if (isDeclaration) { @@ -19021,15 +18980,13 @@ namespace ts { else { error(node, Diagnostics.Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference); } - return; + return true; } - current = current.parent; - } + }); } function checkIfNewTargetIsCapturedInEnclosingScope(node: Node): void { - let current = node; - while (current) { + findAncestor(node, current => { if (getNodeCheckFlags(current) & NodeCheckFlags.CaptureNewTarget) { const isDeclaration = node.kind !== SyntaxKind.Identifier; if (isDeclaration) { @@ -19038,10 +18995,9 @@ namespace ts { else { error(node, Diagnostics.Expression_resolves_to_variable_declaration_newTarget_that_compiler_uses_to_capture_new_target_meta_property_reference); } - return; + return true; } - current = current.parent; - } + }); } function checkCollisionWithCapturedSuperVariable(node: Node, name: Identifier) { @@ -19225,19 +19181,20 @@ namespace ts { return; } // - parameter is wrapped in function-like entity - let current = n; - while (current !== node.initializer) { - if (isFunctionLike(current.parent)) { - return; - } - // computed property names/initializers in instance property declaration of class like entities - // are executed in constructor and thus deferred - if (current.parent.kind === SyntaxKind.PropertyDeclaration && - !(hasModifier(current.parent, ModifierFlags.Static)) && - isClassLike(current.parent.parent)) { - return; - } - current = current.parent; + if (findAncestor( + n, + current => { + if (current === node.initializer) { + return "quit"; + } + return isFunctionLike(current.parent) || + // computed property names/initializers in instance property declaration of class like entities + // are executed in constructor and thus deferred + (current.parent.kind === SyntaxKind.PropertyDeclaration && + !(hasModifier(current.parent, ModifierFlags.Static)) && + isClassLike(current.parent.parent)); + })) { + return; } // fall through to report error } @@ -20035,18 +19992,17 @@ namespace ts { function checkLabeledStatement(node: LabeledStatement) { // Grammar checking if (!checkGrammarStatementInAmbientContext(node)) { - let current = node.parent; - while (current) { - if (isFunctionLike(current)) { - break; - } - if (current.kind === SyntaxKind.LabeledStatement && (current).label.text === node.label.text) { - const sourceFile = getSourceFileOfNode(node); - grammarErrorOnNode(node.label, Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceFile.text, node.label)); - break; - } - current = current.parent; - } + findAncestor(node.parent, + current => { + if (isFunctionLike(current)) { + return "quit"; + } + if (current.kind === SyntaxKind.LabeledStatement && (current).label.text === node.label.text) { + const sourceFile = getSourceFileOfNode(node); + grammarErrorOnNode(node.label, Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceFile.text, node.label)); + return true; + } + }); } // ensure that label is unique @@ -20531,7 +20487,7 @@ namespace ts { errorMessage = Diagnostics.Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function; } - error(derived.valueDeclaration.name, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type)); + error(derived.valueDeclaration.name || derived.valueDeclaration, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type)); } } } @@ -21045,7 +21001,7 @@ namespace ts { } break; } - // fallthrough + // falls through case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.FunctionDeclaration: @@ -21680,6 +21636,7 @@ namespace ts { if (!isExternalOrCommonJsModule(location)) { break; } + // falls through case SyntaxKind.ModuleDeclaration: copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.ModuleMember); break; @@ -21691,7 +21648,8 @@ namespace ts { if (className) { copySymbol(location.symbol, meaning); } - // fall through; this fall-through is necessary because we would like to handle + // falls through + // this fall-through is necessary because we would like to handle // type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: @@ -21980,7 +21938,7 @@ namespace ts { return sig.thisParameter; } } - // fallthrough + // falls through case SyntaxKind.SuperKeyword: const type = isPartOfExpression(node) ? getTypeOfExpression(node) : getTypeFromTypeNode(node); @@ -22008,7 +21966,7 @@ namespace ts { if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) { return resolveExternalModuleName(node, node); } - // Fall through + // falls through case SyntaxKind.NumericLiteral: // index access @@ -22299,11 +22257,7 @@ namespace ts { const symbolIsUmdExport = symbolFile !== referenceFile; return symbolIsUmdExport ? undefined : symbolFile; } - for (let n = node.parent; n; n = n.parent) { - if (isModuleOrEnumDeclaration(n) && getSymbolOfNode(n) === parentSymbol) { - return n; - } - } + return findAncestor(node.parent, n => isModuleOrEnumDeclaration(n) && getSymbolOfNode(n) === parentSymbol) as ModuleDeclaration | EnumDeclaration; } } } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 23751186677..358b910f2f2 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -224,6 +224,25 @@ namespace ts { } return undefined; } + /** + * Iterates through the parent chain of a node and performs the callback on each parent until the callback + * returns a truthy value, then returns that value. + * If no such value is found, it applies the callback until the parent pointer is undefined or the callback returns "quit" + * At that point findAncestor returns undefined. + */ + export function findAncestor(node: Node, callback: (element: Node) => boolean | "quit"): Node { + while (node) { + const result = callback(node); + if (result === "quit") { + return undefined; + } + else if (result) { + return node; + } + node = node.parent; + } + return undefined; + } export function zipWith(arrayA: T[], arrayB: U[], callback: (a: T, b: U, index: number) => void): void { Debug.assert(arrayA.length === arrayB.length); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5f7076c949d..a1200b6a072 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3197,6 +3197,10 @@ "category": "Message", "code": 6181 }, + "Scoped package detected, looking in '{0}'": { + "category": "Message", + "code": "6182" + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 1603f08bb5f..d511b31b331 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -378,7 +378,7 @@ namespace ts { directoryPathMap.set(parent, result); current = parent; - if (current == commonPrefix) { + if (current === commonPrefix) { break; } } @@ -954,10 +954,25 @@ namespace ts { } nodeModulesAtTypesExists = false; } - return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, moduleName, nodeModulesAtTypes, nodeModulesAtTypesExists, failedLookupLocations, state); + return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, mangleScopedPackage(moduleName, state), nodeModulesAtTypes, nodeModulesAtTypesExists, failedLookupLocations, state); } } + /** For a scoped package, we must look in `@types/foo__bar` instead of `@types/@foo/bar`. */ + function mangleScopedPackage(moduleName: string, state: ModuleResolutionState): string { + if (startsWith(moduleName, "@")) { + const replaceSlash = moduleName.replace(ts.directorySeparator, "__"); + if (replaceSlash !== moduleName) { + const mangled = replaceSlash.slice(1); // Take off the "@" + if (state.traceEnabled) { + trace(state.host, Diagnostics.Scoped_package_detected_looking_in_0, mangled); + } + return mangled; + } + } + return moduleName; + } + function tryFindNonRelativeModuleNameInCache(cache: PerModuleNameCache | undefined, moduleName: string, containingDirectory: string, traceEnabled: boolean, host: ModuleResolutionHost): SearchResult { const result = cache && cache.get(containingDirectory); if (result) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 08144e79299..93aa13bd415 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -57,7 +57,7 @@ namespace ts { // The visitXXX functions could be written as local functions that close over the cbNode and cbNodeArray // callback parameters, but that causes a closure allocation for each invocation with noticeable effects // on performance. - const visitNodes: (cb: (node: Node | Node[]) => T, nodes: Node[]) => T = cbNodeArray ? visitNodeArray : visitEachNode; + const visitNodes: (cb: ((node: Node) => T) | ((node: Node[]) => T), nodes: Node[]) => T = cbNodeArray ? visitNodeArray : visitEachNode; const cbNodes = cbNodeArray || cbNode; switch (node.kind) { case SyntaxKind.QualifiedName: @@ -3573,6 +3573,7 @@ namespace ts { if (isAwaitExpression()) { return parseAwaitExpression(); } + // falls through default: return parseIncrementExpression(); } @@ -3606,8 +3607,8 @@ namespace ts { if (sourceFile.languageVariant !== LanguageVariant.JSX) { return false; } - // We are in JSX context and the token is part of JSXElement. - // Fall through + // We are in JSX context and the token is part of JSXElement. + // falls through default: return true; } @@ -6571,7 +6572,8 @@ namespace ts { indent += scanner.getTokenText().length; break; } - // FALLTHROUGH otherwise to record the * as a comment + // record the * as a comment + // falls through default: state = JSDocState.SavingComments; // leading identifiers start recording as well pushComment(scanner.getTokenText()); @@ -6797,6 +6799,7 @@ namespace ts { break; case SyntaxKind.Identifier: canParseTag = false; + break; case SyntaxKind.EndOfFileToken: break; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index f2d44adb1f1..0971adfc098 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -557,7 +557,7 @@ namespace ts { // combine results of resolutions and predicted results let j = 0; for (let i = 0; i < result.length; i++) { - if (result[i] == predictedToResolveToAmbientModuleMarker) { + if (result[i] === predictedToResolveToAmbientModuleMarker) { result[i] = undefined; } else { @@ -930,20 +930,22 @@ namespace ts { */ function shouldReportDiagnostic(diagnostic: Diagnostic) { const { file, start } = diagnostic; - const lineStarts = getLineStarts(file); - let { line } = computeLineAndCharacterOfPosition(lineStarts, start); - while (line > 0) { - const previousLineText = file.text.slice(lineStarts[line - 1], lineStarts[line]); - const result = ignoreDiagnosticCommentRegEx.exec(previousLineText); - if (!result) { - // non-empty line - return true; + if (file) { + const lineStarts = getLineStarts(file); + let { line } = computeLineAndCharacterOfPosition(lineStarts, start); + while (line > 0) { + const previousLineText = file.text.slice(lineStarts[line - 1], lineStarts[line]); + const result = ignoreDiagnosticCommentRegEx.exec(previousLineText); + if (!result) { + // non-empty line + return true; + } + if (result[3]) { + // @ts-ignore + return false; + } + line--; } - if (result[3]) { - // @ts-ignore - return false; - } - line--; } return true; } @@ -967,8 +969,7 @@ namespace ts { diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?")); return; } - - // Pass through + // falls through case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -1048,7 +1049,7 @@ namespace ts { diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file)); return; } - // pass through + // falls through case SyntaxKind.VariableStatement: // Check modifiers if (nodes === (parent).modifiers) { @@ -1096,7 +1097,8 @@ namespace ts { if (isConstValid) { continue; } - // Fallthrough to report error + // to report error, + // falls through case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: @@ -1364,7 +1366,7 @@ namespace ts { // If the file was previously found via a node_modules search, but is now being processed as a root file, // then everything it sucks in may also be marked incorrectly, and needs to be checked again. - if (file && sourceFilesFoundSearchingNodeModules.get(file.path) && currentNodeModulesDepth == 0) { + if (file && sourceFilesFoundSearchingNodeModules.get(file.path) && currentNodeModulesDepth === 0) { sourceFilesFoundSearchingNodeModules.set(file.path, false); if (!options.noResolve) { processReferencedFiles(file, isDefaultLib); diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 41c48700a9a..406405600f1 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -308,6 +308,7 @@ namespace ts { if (text.charCodeAt(pos) === CharacterCodes.lineFeed) { pos++; } + // falls through case CharacterCodes.lineFeed: result.push(lineStart); lineStart = pos; @@ -454,6 +455,7 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) { pos++; } + // falls through case CharacterCodes.lineFeed: pos++; if (stopAfterLineBreak) { @@ -625,6 +627,7 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) { pos++; } + // falls through case CharacterCodes.lineFeed: pos++; if (trailing) { @@ -1072,7 +1075,7 @@ namespace ts { if (pos < end && text.charCodeAt(pos) === CharacterCodes.lineFeed) { pos++; } - // fall through + // falls through case CharacterCodes.lineFeed: case CharacterCodes.lineSeparator: case CharacterCodes.paragraphSeparator: @@ -1459,6 +1462,7 @@ namespace ts { // This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero // can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being // permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do). + // falls through case CharacterCodes._1: case CharacterCodes._2: case CharacterCodes._3: diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index cde4fcad57e..5711d9f1116 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -479,8 +479,8 @@ namespace ts { // module is imported only for side-effects, no emit required break; } + // falls through - // fall-through case SyntaxKind.ImportEqualsDeclaration: Debug.assert(importVariableName !== undefined); // save import into the local diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index b32a7be30d9..8981da65ba3 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -30,7 +30,7 @@ namespace ts { } function reportEmittedFiles(files: string[]): void { - if (!files || files.length == 0) { + if (!files || files.length === 0) { return; } @@ -282,7 +282,7 @@ namespace ts { // When the configFileName is just "tsconfig.json", the watched directory should be // the current directory; if there is a given "project" parameter, then the configFileName // is an absolute file name. - directory == "" ? "." : directory, + directory === "" ? "." : directory, watchedDirectoryChanged, /*recursive*/ true); } } @@ -334,7 +334,7 @@ namespace ts { // When the configFileName is just "tsconfig.json", the watched directory should be // the current directory; if there is a given "project" parameter, then the configFileName // is an absolute file name. - directory == "" ? "." : directory, + directory === "" ? "." : directory, watchedDirectoryChanged, /*recursive*/ true); } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3b4b87c956f..f34c15ee346 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -674,6 +674,7 @@ namespace ts { // At this point, node is either a qualified name or an identifier Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression, "'node' was expected to be a qualified name, identifier or property access in 'isPartOfTypeNode'."); + // falls through case SyntaxKind.QualifiedName: case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ThisKeyword: @@ -783,6 +784,7 @@ namespace ts { if (operand) { traverse(operand); } + return; case SyntaxKind.EnumDeclaration: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.ModuleDeclaration: @@ -1000,7 +1002,7 @@ namespace ts { if (!includeArrowFunctions) { continue; } - // Fall through + // falls through case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ModuleDeclaration: @@ -1059,6 +1061,7 @@ namespace ts { if (!stopOnFunctions) { continue; } + // falls through case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: @@ -1258,7 +1261,7 @@ namespace ts { if (node.parent.kind === SyntaxKind.TypeQuery || isJSXTagName(node)) { return true; } - // fall through + // falls through case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.ThisKeyword: @@ -1940,7 +1943,7 @@ namespace ts { if (node.asteriskToken) { flags |= FunctionFlags.Generator; } - // fall through + // falls through case SyntaxKind.ArrowFunction: if (hasModifier(node, ModifierFlags.Async)) { flags |= FunctionFlags.Async; @@ -4428,7 +4431,7 @@ namespace ts { newEndN = Math.max(newEnd2, newEnd2 + (newEnd1 - oldEnd2)); } - return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength:*/ newEndN - oldStartN); + return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength*/ newEndN - oldStartN); } export function getTypeParameterOwner(d: Declaration): Declaration { @@ -4604,7 +4607,7 @@ namespace ts { */ export function getParseTreeNode(node: Node, nodeTest?: (node: Node) => node is T): T; export function getParseTreeNode(node: Node, nodeTest?: (node: Node) => boolean): Node { - if (node == undefined || isParseTreeNode(node)) { + if (node === undefined || isParseTreeNode(node)) { return node; } diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 297d2cc0dde..7850155ed25 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -322,7 +322,7 @@ namespace ts { nodesVisitor((node).types, visitor, isTypeNode)); case SyntaxKind.ParenthesizedType: - Debug.fail("not implemented."); + throw Debug.fail("not implemented."); case SyntaxKind.TypeOperator: return updateTypeOperatorNode(node, visitNode((node).type, visitor, isTypeNode)); @@ -885,7 +885,7 @@ namespace ts { return initial; } - const reduceNodes: (nodes: NodeArray, f: (memo: T, node: Node | NodeArray) => T, initial: T) => T = cbNodeArray ? reduceNodeArray : reduceLeft; + const reduceNodes: (nodes: NodeArray, f: ((memo: T, node: Node) => T) | ((memo: T, node: NodeArray) => T), initial: T) => T = cbNodeArray ? reduceNodeArray : reduceLeft; const cbNodes = cbNodeArray || cbNode; const kind = node.kind; @@ -1289,6 +1289,7 @@ namespace ts { case SyntaxKind.JsxAttributes: result = reduceNodes((node).properties, cbNodes, result); + break; case SyntaxKind.JsxClosingElement: result = reduceNode((node).tagName, cbNode, result); @@ -1310,7 +1311,7 @@ namespace ts { // Clauses case SyntaxKind.CaseClause: result = reduceNode((node).expression, cbNode, result); - // fall-through + // falls through case SyntaxKind.DefaultClause: result = reduceNodes((node).statements, cbNodes, result); @@ -1344,6 +1345,7 @@ namespace ts { case SyntaxKind.EnumMember: result = reduceNode((node).name, cbNode, result); result = reduceNode((node).initializer, cbNode, result); + break; // Top-level nodes case SyntaxKind.SourceFile: diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index c0e950c4f38..a56d21ae345 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2367,13 +2367,13 @@ namespace FourSlash { public verifyImportFixAtPosition(expectedTextArray: string[], errorCode?: number) { const ranges = this.getRanges(); - if (ranges.length == 0) { + if (ranges.length === 0) { this.raiseError("At least one range should be specified in the testfile."); } const codeFixes = this.getCodeFixActions(this.activeFile.fileName, errorCode); - if (!codeFixes || codeFixes.length == 0) { + if (!codeFixes || codeFixes.length === 0) { this.raiseError("No codefixes returned."); } @@ -2738,7 +2738,7 @@ namespace FourSlash { private assertItemInCompletionList(items: ts.CompletionEntry[], name: string, text?: string, documentation?: string, kind?: string, spanIndex?: number) { for (const item of items) { if (item.name === name) { - if (documentation != undefined || text !== undefined) { + if (documentation !== undefined || text !== undefined) { const details = this.getCompletionEntryDetails(item.name); if (documentation !== undefined) { @@ -2989,9 +2989,8 @@ ${code} } } } - // TODO: should be '==='? } - else if (line == "" || lineLength === 0) { + else if (line === "" || lineLength === 0) { // Previously blank lines between fourslash content caused it to be considered as 2 files, // Remove this behavior since it just causes errors now } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 2c4eef1739d..c0ef2672b27 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1933,7 +1933,7 @@ namespace Harness { } const parentDirectory = IO.directoryName(dirName); - if (parentDirectory != "") { + if (parentDirectory !== "") { createDirectoryStructure(parentDirectory); } IO.createDirectory(dirName); diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index f1cc992c4a7..b0efcf4c389 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -111,8 +111,7 @@ class ProjectRunner extends RunnerBase { else if (url.indexOf(diskProjectPath) === 0) { // Replace the disk specific path into the project root path url = url.substr(diskProjectPath.length); - // TODO: should be '!=='? - if (url.charCodeAt(0) != ts.CharacterCodes.slash) { + if (url.charCodeAt(0) !== ts.CharacterCodes.slash) { url = "/" + url; } } diff --git a/src/harness/sourceMapRecorder.ts b/src/harness/sourceMapRecorder.ts index aa66d713e1c..bb5126fb352 100644 --- a/src/harness/sourceMapRecorder.ts +++ b/src/harness/sourceMapRecorder.ts @@ -50,11 +50,11 @@ namespace Harness.SourceMapRecorder { return true; } - if (sourceMapMappings.charAt(decodingIndex) == ",") { + if (sourceMapMappings.charAt(decodingIndex) === ",") { return true; } - if (sourceMapMappings.charAt(decodingIndex) == ";") { + if (sourceMapMappings.charAt(decodingIndex) === ";") { return true; } @@ -117,7 +117,7 @@ namespace Harness.SourceMapRecorder { } while (decodingIndex < sourceMapMappings.length) { - if (sourceMapMappings.charAt(decodingIndex) == ";") { + if (sourceMapMappings.charAt(decodingIndex) === ";") { // New line decodeOfEncodedMapping.emittedLine++; decodeOfEncodedMapping.emittedColumn = 1; @@ -125,7 +125,7 @@ namespace Harness.SourceMapRecorder { continue; } - if (sourceMapMappings.charAt(decodingIndex) == ",") { + if (sourceMapMappings.charAt(decodingIndex) === ",") { // Next entry is on same line - no action needed decodingIndex++; continue; diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 81931a2de41..66d9cb087b6 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -3228,7 +3228,7 @@ namespace ts.projectSystem { checkNumberOfInferredProjects(projectService, 1); const configuredProject = projectService.configuredProjects[0]; - assert.isTrue(configuredProject.getFileNames().length == 0); + assert.isTrue(configuredProject.getFileNames().length === 0); const inferredProject = projectService.inferredProjects[0]; assert.isTrue(inferredProject.containsFile(file1.path)); diff --git a/src/harness/unittests/versionCache.ts b/src/harness/unittests/versionCache.ts index 17a70f59d59..ca64ea1118f 100644 --- a/src/harness/unittests/versionCache.ts +++ b/src/harness/unittests/versionCache.ts @@ -278,7 +278,7 @@ and grew 1cm per day`; const insertString = testContent.substring(rsa[i], rsa[i] + las[i]); svc.edit(ersa[i], elas[i], insertString); checkText = editFlat(ersa[i], elas[i], insertString, checkText); - if (0 == (i % 4)) { + if (0 === (i % 4)) { const snap = svc.getSnapshot(); const snapText = snap.getText(0, checkText.length); assert.equal(checkText, snapText); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index f4f1e66e1ff..d45bb283384 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -257,7 +257,7 @@ namespace ts.server { startWatchingContainingDirectoriesForFile(fileName: string, project: InferredProject, callback: (fileName: string) => void) { let currentPath = getDirectoryPath(fileName); let parentPath = getDirectoryPath(currentPath); - while (currentPath != parentPath) { + while (currentPath !== parentPath) { if (!this.directoryWatchersForTsconfig.has(currentPath)) { this.projectService.logger.info(`Add watcher for: ${currentPath}`); this.directoryWatchersForTsconfig.set(currentPath, this.projectService.host.watchDirectory(currentPath, callback)); @@ -618,7 +618,7 @@ namespace ts.server { */ private onConfigFileAddedForInferredProject(fileName: string) { // TODO: check directory separators - if (getBaseFileName(fileName) != "tsconfig.json") { + if (getBaseFileName(fileName) !== "tsconfig.json") { this.logger.info(`${fileName} is not tsconfig.json`); return; } @@ -1033,7 +1033,7 @@ namespace ts.server { const scriptKind = propertyReader.getScriptKind(f); const hasMixedContent = propertyReader.hasMixedContent(f, this.hostConfiguration.extraFileExtensions); if (this.host.fileExists(rootFilename)) { - const info = this.getOrCreateScriptInfoForNormalizedPath(toNormalizedPath(rootFilename), /*openedByClient*/ clientFileName == rootFilename, /*fileContent*/ undefined, scriptKind, hasMixedContent); + const info = this.getOrCreateScriptInfoForNormalizedPath(toNormalizedPath(rootFilename), /*openedByClient*/ clientFileName === rootFilename, /*fileContent*/ undefined, scriptKind, hasMixedContent); project.addRoot(info); } else { diff --git a/src/server/project.ts b/src/server/project.ts index b92e8e84972..09c8d74c8c7 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -643,7 +643,7 @@ namespace ts.server { // check if requested version is the same that we have reported last time if (this.lastReportedFileNames && lastKnownVersion === this.lastReportedVersion) { // if current structure version is the same - return info without any changes - if (this.projectStructureVersion == this.lastReportedVersion && !updatedFileNames) { + if (this.projectStructureVersion === this.lastReportedVersion && !updatedFileNames) { return { info, projectErrors: this.projectErrors }; } // compute and return the difference diff --git a/src/server/scriptVersionCache.ts b/src/server/scriptVersionCache.ts index 7f09bcd549b..35266591098 100644 --- a/src/server/scriptVersionCache.ts +++ b/src/server/scriptVersionCache.ts @@ -79,7 +79,7 @@ namespace ts.server { const lm = LineIndex.linesFromText(insertedText); const lines = lm.lines; if (lines.length > 1) { - if (lines[lines.length - 1] == "") { + if (lines[lines.length - 1] === "") { lines.length--; } } @@ -570,7 +570,7 @@ namespace ts.server { } if (this.checkEdits) { const updatedText = this.getText(0, this.root.charCount()); - Debug.assert(checkText == updatedText, "buffer edit mismatch"); + Debug.assert(checkText === updatedText, "buffer edit mismatch"); } return walker.lineIndex; } diff --git a/src/server/server.ts b/src/server/server.ts index 433c7e16ab1..79cfc3882ae 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -380,7 +380,7 @@ namespace ts.server { } this.projectService.updateTypingsForProject(response); - if (response.kind == ActionSet && this.socket) { + if (response.kind === ActionSet && this.socket) { this.sendEvent(0, "setTypings", response); } } @@ -401,7 +401,9 @@ namespace ts.server { byteLength: Buffer.byteLength, hrtime: process.hrtime, logger, - canUseEvents}); + canUseEvents, + globalPlugins: options.globalPlugins, + pluginProbeLocations: options.pluginProbeLocations}); if (telemetryEnabled && typingsInstaller) { typingsInstaller.setTelemetrySender(this); diff --git a/src/server/session.ts b/src/server/session.ts index d4dc371b16b..742f8a3c228 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -49,7 +49,7 @@ namespace ts.server { if (a.file < b.file) { return -1; } - else if (a.file == b.file) { + else if (a.file === b.file) { const n = compareNumber(a.start.line, b.start.line); if (n === 0) { return compareNumber(a.start.offset, b.start.offset); @@ -1128,7 +1128,7 @@ namespace ts.server { // getFormattingEditsAfterKeystroke either empty or pertaining // only to the previous line. If all this is true, then // add edits necessary to properly indent the current line. - if ((args.key == "\n") && ((!edits) || (edits.length === 0) || allEditsBeforePos(edits, position))) { + if ((args.key === "\n") && ((!edits) || (edits.length === 0) || allEditsBeforePos(edits, position))) { const lineInfo = scriptInfo.getLineInfo(args.line); if (lineInfo && (lineInfo.leaf) && (lineInfo.leaf.text)) { const lineText = lineInfo.leaf.text; @@ -1137,10 +1137,10 @@ namespace ts.server { let hasIndent = 0; let i: number, len: number; for (i = 0, len = lineText.length; i < len; i++) { - if (lineText.charAt(i) == " ") { + if (lineText.charAt(i) === " ") { hasIndent++; } - else if (lineText.charAt(i) == "\t") { + else if (lineText.charAt(i) === "\t") { hasIndent += formatOptions.tabSize; } else { @@ -1543,7 +1543,7 @@ namespace ts.server { const normalizedFileName = toNormalizedPath(fileName); const project = this.projectService.getDefaultProjectForFile(normalizedFileName, /*refreshInferredProjects*/ true); for (const fileNameInProject of fileNamesInProject) { - if (this.getCanonicalFileName(fileNameInProject) == this.getCanonicalFileName(fileName)) + if (this.getCanonicalFileName(fileNameInProject) === this.getCanonicalFileName(fileName)) highPriorityFiles.push(fileNameInProject); else { const info = this.projectService.getScriptInfo(fileNameInProject); @@ -1564,7 +1564,7 @@ namespace ts.server { const checkList = fileNamesInProject.map(fileName => ({ fileName, project })); // Project level error analysis runs on background files too, therefore // doesn't require the file to be opened - this.updateErrorCheck(next, checkList, this.changeSeq, (n) => n == this.changeSeq, delay, 200, /*requireOpen*/ false); + this.updateErrorCheck(next, checkList, this.changeSeq, (n) => n === this.changeSeq, delay, 200, /*requireOpen*/ false); } } diff --git a/src/server/typingsCache.ts b/src/server/typingsCache.ts index 9379ae82d0e..a97b12ff7a8 100644 --- a/src/server/typingsCache.ts +++ b/src/server/typingsCache.ts @@ -61,7 +61,7 @@ namespace ts.server { function compilerOptionsChanged(opt1: CompilerOptions, opt2: CompilerOptions): boolean { // TODO: add more relevant properties - return opt1.allowJs != opt2.allowJs; + return opt1.allowJs !== opt2.allowJs; } function unresolvedImportsChanged(imports1: SortedReadonlyArray, imports2: SortedReadonlyArray): boolean { diff --git a/src/server/typingsInstaller/nodeTypingsInstaller.ts b/src/server/typingsInstaller/nodeTypingsInstaller.ts index 1018b37d90d..895a4e17cc7 100644 --- a/src/server/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/server/typingsInstaller/nodeTypingsInstaller.ts @@ -31,7 +31,7 @@ namespace ts.server.typingsInstaller { } function getNPMLocation(processName: string) { - if (path.basename(processName).indexOf("node") == 0) { + if (path.basename(processName).indexOf("node") === 0) { return `"${path.join(path.dirname(process.argv[0]), "npm")}"`; } else { diff --git a/src/server/utilities.ts b/src/server/utilities.ts index 8784efff750..ffc09f29ccd 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -219,7 +219,7 @@ namespace ts.server { } public scheduleCollect() { - if (!this.host.gc || this.timerId != undefined) { + if (!this.host.gc || this.timerId !== undefined) { // no global.gc or collection was already scheduled - skip this request return; } diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 1f6bec41109..e47f6d016c7 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -97,7 +97,7 @@ namespace ts.BreakpointResolver { if (isFunctionBlock(node)) { return spanInFunctionBlock(node); } - // Fall through + // falls through case SyntaxKind.ModuleBlock: return spanInBlock(node); @@ -186,6 +186,7 @@ namespace ts.BreakpointResolver { if (getModuleInstanceState(node) !== ModuleInstanceState.Instantiated) { return undefined; } + // falls through case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: @@ -264,7 +265,7 @@ namespace ts.BreakpointResolver { // a or ...c or d: x from // [a, b, ...c] or { a, b } or { d: x } from destructuring pattern if ((node.kind === SyntaxKind.Identifier || - node.kind == SyntaxKind.SpreadElement || + node.kind === SyntaxKind.SpreadElement || node.kind === SyntaxKind.PropertyAssignment || node.kind === SyntaxKind.ShorthandPropertyAssignment) && isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent)) { @@ -473,6 +474,7 @@ namespace ts.BreakpointResolver { if (getModuleInstanceState(block.parent) !== ModuleInstanceState.Instantiated) { return undefined; } + // falls through // Set on parent if on same line otherwise on first statement case SyntaxKind.WhileStatement: @@ -582,6 +584,7 @@ namespace ts.BreakpointResolver { if (getModuleInstanceState(node.parent.parent) !== ModuleInstanceState.Instantiated) { return undefined; } + // falls through case SyntaxKind.EnumDeclaration: case SyntaxKind.ClassDeclaration: @@ -593,7 +596,7 @@ namespace ts.BreakpointResolver { // Span on close brace token return textSpan(node); } - // fall through + // falls through case SyntaxKind.CatchClause: return spanInNode(lastOrUndefined((node.parent).statements)); diff --git a/src/services/classifier.ts b/src/services/classifier.ts index c15b65b0c39..0deff253212 100644 --- a/src/services/classifier.ts +++ b/src/services/classifier.ts @@ -160,7 +160,7 @@ namespace ts { case EndOfLineState.InTemplateMiddleOrTail: text = "}\n" + text; offset = 2; - // fallthrough + // falls through case EndOfLineState.InTemplateSubstitutionPosition: templateStack.push(SyntaxKind.TemplateHead); break; diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index a808786230d..8e1d0ac2f29 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -14,7 +14,7 @@ namespace ts.codefix { // ^^^^^^^ const token = getTokenAtPosition(sourceFile, start); - if (token.kind != SyntaxKind.Identifier) { + if (token.kind !== SyntaxKind.Identifier) { return undefined; } diff --git a/src/services/codefixes/fixClassSuperMustPrecedeThisAccess.ts b/src/services/codefixes/fixClassSuperMustPrecedeThisAccess.ts index fc2be3cd0c2..2217dda8b0c 100644 --- a/src/services/codefixes/fixClassSuperMustPrecedeThisAccess.ts +++ b/src/services/codefixes/fixClassSuperMustPrecedeThisAccess.ts @@ -18,7 +18,7 @@ namespace ts.codefix { // figure out if the `this` access is actually inside the supercall // i.e. super(this.a), since in that case we won't suggest a fix - if (superCall.expression && superCall.expression.kind == SyntaxKind.CallExpression) { + if (superCall.expression && superCall.expression.kind === SyntaxKind.CallExpression) { const arguments = (superCall.expression).arguments; for (let i = 0; i < arguments.length; i++) { if ((arguments[i]).expression === token) { diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index e10794997ca..78c27a1276b 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -42,12 +42,13 @@ namespace ts.codefix { switch (this.compareModuleSpecifiers(existingAction.moduleSpecifier, newAction.moduleSpecifier)) { case ModuleSpecifierComparison.Better: - // the new one is not worth considering if it is a new improt. + // the new one is not worth considering if it is a new import. // However if it is instead a insertion into existing import, the user might want to use // the module specifier even it is worse by our standards. So keep it. if (newAction.kind === "NewImport") { return; } + // falls through case ModuleSpecifierComparison.Equal: // the current one is safe. But it is still possible that the new one is worse // than another existing one. For example, you may have new imports from "./foo/bar" diff --git a/src/services/codefixes/unusedIdentifierFixes.ts b/src/services/codefixes/unusedIdentifierFixes.ts index 0daeea5df62..e1debfa4ffb 100644 --- a/src/services/codefixes/unusedIdentifierFixes.ts +++ b/src/services/codefixes/unusedIdentifierFixes.ts @@ -58,6 +58,8 @@ namespace ts.codefix { return deleteNodeInList(token.parent); } } + // TODO: #14885 + // falls through case SyntaxKind.TypeParameter: const typeParameters = (token.parent.parent).typeParameters; @@ -125,7 +127,7 @@ namespace ts.codefix { case SyntaxKind.NamespaceImport: const namespaceImport = token.parent; - if (namespaceImport.name == token && !(namespaceImport.parent).name) { + if (namespaceImport.name === token && !(namespaceImport.parent).name) { const importDecl = getAncestor(namespaceImport, SyntaxKind.ImportDeclaration); return deleteNode(importDecl); } diff --git a/src/services/completions.ts b/src/services/completions.ts index 2073b950bee..6ac3762b4c7 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -487,7 +487,7 @@ namespace ts.Completions { // It has a left-hand side, so we're not in an opening JSX tag. break; } - // fall through + // falls through case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.JsxElement: @@ -1311,7 +1311,7 @@ namespace ts.Completions { } function isEqualityOperatorKind(kind: SyntaxKind) { - return kind == SyntaxKind.EqualsEqualsToken || + return kind === SyntaxKind.EqualsEqualsToken || kind === SyntaxKind.ExclamationEqualsToken || kind === SyntaxKind.EqualsEqualsEqualsToken || kind === SyntaxKind.ExclamationEqualsEqualsToken; diff --git a/src/services/documentHighlights.ts b/src/services/documentHighlights.ts index 047e665d7a5..a8afc46d736 100644 --- a/src/services/documentHighlights.ts +++ b/src/services/documentHighlights.ts @@ -233,7 +233,7 @@ namespace ts.DocumentHighlights { if (statement.kind === SyntaxKind.ContinueStatement) { continue; } - // Fall through. + // falls through case SyntaxKind.ForStatement: case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 98e601ebb06..fd717fc546e 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -7,7 +7,7 @@ namespace ts.FindAllReferences { references: Entry[]; } - type Definition = + export type Definition = | { type: "symbol"; symbol: Symbol; node: Node } | { type: "label"; node: Identifier } | { type: "keyword"; node: ts.Node } @@ -20,7 +20,7 @@ namespace ts.FindAllReferences { node: Node; isInString?: true; } - interface SpanEntry { + export interface SpanEntry { type: "span"; fileName: string; textSpan: TextSpan; @@ -1234,7 +1234,7 @@ namespace ts.FindAllReferences.Core { if (isObjectLiteralMethod(searchSpaceNode)) { break; } - // fall through + // falls through case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.Constructor: @@ -1247,7 +1247,7 @@ namespace ts.FindAllReferences.Core { if (isExternalModule(searchSpaceNode)) { return undefined; } - // Fall through + // falls through case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: break; diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 3a4547d4597..d7c32da5e8d 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -483,9 +483,8 @@ namespace ts.formatting { case SyntaxKind.MethodDeclaration: if ((node).asteriskToken) { return SyntaxKind.AsteriskToken; - }/* - fall-through - */ + } + // falls through case SyntaxKind.PropertyDeclaration: case SyntaxKind.Parameter: return (node).name.kind; diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 510f78c3f39..5080de2edcc 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -146,7 +146,7 @@ namespace ts.OutliningElementsCollector { }); break; } - // Fallthrough. + // falls through case SyntaxKind.ModuleBlock: { const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); diff --git a/src/services/services.ts b/src/services/services.ts index 5624c48a535..8f2cbb22379 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -659,7 +659,7 @@ namespace ts { if (!hasModifier(node, ModifierFlags.ParameterPropertyModifier)) { break; } - // fall through + // falls through case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: { const decl = node; @@ -670,6 +670,7 @@ namespace ts { if (decl.initializer) visit(decl.initializer); } + // falls through case SyntaxKind.EnumMember: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -2079,7 +2080,7 @@ namespace ts { if (node.parent.kind === SyntaxKind.ComputedPropertyName) { return isObjectLiteralElement(node.parent.parent) ? node.parent.parent : undefined; } - // intentionally fall through + // falls through case SyntaxKind.Identifier: return isObjectLiteralElement(node.parent) && (node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression || node.parent.parent.kind === SyntaxKind.JsxAttributes) && diff --git a/src/services/shims.ts b/src/services/shims.ts index 37b3fbc3d94..7588e16f3dc 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -37,7 +37,7 @@ namespace ts { * * Or undefined value if there was no change. */ - getChangeRange(oldSnapshot: ScriptSnapshotShim): string; + getChangeRange(oldSnapshot: ScriptSnapshotShim): string | undefined; /** Releases all resources held by this script snapshot */ dispose?(): void; @@ -292,8 +292,7 @@ namespace ts { public getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange { const oldSnapshotShim = oldSnapshot; const encoded = this.scriptSnapshotShim.getChangeRange(oldSnapshotShim.scriptSnapshotShim); - // TODO: should this be '==='? - if (encoded == null) { + if (encoded === null) { return null; } @@ -381,8 +380,7 @@ namespace ts { public getCompilationSettings(): CompilerOptions { const settingsJson = this.shimHost.getCompilationSettings(); - // TODO: should this be '==='? - if (settingsJson == null || settingsJson == "") { + if (settingsJson === null || settingsJson === "") { throw Error("LanguageServiceShimHostAdapter.getCompilationSettings: empty compilationSettings"); } const compilerOptions = JSON.parse(settingsJson); @@ -416,7 +414,7 @@ namespace ts { public getLocalizedDiagnosticMessages(): any { const diagnosticMessagesJson = this.shimHost.getLocalizedDiagnosticMessages(); - if (diagnosticMessagesJson == null || diagnosticMessagesJson == "") { + if (diagnosticMessagesJson === null || diagnosticMessagesJson === "") { return null; } diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 7b2abc6123c..1487bb410a5 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -56,7 +56,7 @@ namespace ts.SignatureHelp { // break; // case TypeScript.SyntaxKind.CommaToken: - // if (stack == 0) { + // if (stack === 0) { // argumentIndex++; // } diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index d7056cfdca2..aa805da129a 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -465,7 +465,7 @@ namespace ts.textChanges { change.options.indentation !== undefined ? change.options.indentation : change.useIndentationFromFile - ? formatting.SmartIndenter.getIndentation(change.range.pos, sourceFile, formatOptions, posStartsLine || (change.options.prefix == this.newLineCharacter)) + ? formatting.SmartIndenter.getIndentation(change.range.pos, sourceFile, formatOptions, posStartsLine || (change.options.prefix === this.newLineCharacter)) : 0; const delta = change.options.delta !== undefined diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 815faac7417..56832b90d1f 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -441,7 +441,7 @@ namespace ts { if (!(n).arguments) { return true; } - // fall through + // falls through case SyntaxKind.CallExpression: case SyntaxKind.ParenthesizedExpression: case SyntaxKind.ParenthesizedType: @@ -902,10 +902,10 @@ namespace ts { // Internally, we represent the end of the comment at the newline and closing '/', respectively. return predicate ? forEach(commentRanges, c => c.pos < position && - (c.kind == SyntaxKind.SingleLineCommentTrivia ? position <= c.end : position < c.end) && + (c.kind === SyntaxKind.SingleLineCommentTrivia ? position <= c.end : position < c.end) && predicate(c)) : forEach(commentRanges, c => c.pos < position && - (c.kind == SyntaxKind.SingleLineCommentTrivia ? position <= c.end : position < c.end)); + (c.kind === SyntaxKind.SingleLineCommentTrivia ? position <= c.end : position < c.end)); } return false; diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt new file mode 100644 index 00000000000..0e8605efafd --- /dev/null +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt @@ -0,0 +1,113 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(71,1): error TS2322: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U'. + Types of parameters 'y' and 'y' are incompatible. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type 'Base' is not assignable to type '{ foo: string; bing: number; }'. + Property 'bing' is missing in type 'Base'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts (1 errors) ==== + // these are all permitted with the current rules, since we do not do contextual signature instantiation + + class Base { foo: string; } + class Derived extends Base { bar: string; } + class Derived2 extends Derived { baz: string; } + class OtherDerived extends Base { bing: string; } + + var a: (x: number) => number[]; + var a2: (x: number) => string[]; + var a3: (x: number) => void; + var a4: (x: string, y: number) => string; + var a5: (x: (arg: string) => number) => string; + var a6: (x: (arg: Base) => Derived) => Base; + var a7: (x: (arg: Base) => Derived) => (r: Base) => Derived; + var a8: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; + var a9: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; + var a10: (...x: Derived[]) => Derived; + var a11: (x: { foo: string }, y: { foo: string; bar: string }) => Base; + var a12: (x: Array, y: Array) => Array; + var a13: (x: Array, y: Array) => Array; + var a14: (x: { a: string; b: number }) => Object; + var a15: { + (x: number): number[]; + (x: string): string[]; + } + var a16: { + (x: T): number[]; + (x: U): number[]; + } + var a17: { + (x: (a: number) => number): number[]; + (x: (a: string) => string): string[]; + }; + var a18: { + (x: { + (a: number): number; + (a: string): string; + }): any[]; + (x: { + (a: boolean): boolean; + (a: Date): Date; + }): any[]; + } + + var b: (x: T) => T[]; + a = b; // ok + b = a; // ok + var b2: (x: T) => string[]; + a2 = b2; // ok + b2 = a2; // ok + var b3: (x: T) => T; + a3 = b3; // ok + b3 = a3; // ok + var b4: (x: T, y: U) => T; + a4 = b4; // ok + b4 = a4; // ok + var b5: (x: (arg: T) => U) => T; + a5 = b5; // ok + b5 = a5; // ok + var b6: (x: (arg: T) => U) => T; + a6 = b6; // ok + b6 = a6; // ok + var b7: (x: (arg: T) => U) => (r: T) => U; + a7 = b7; // ok + b7 = a7; // ok + var b8: (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; + a8 = b8; // ok + b8 = a8; // ok + var b9: (x: (arg: T) => U, y: (arg2: { foo: string; bing: number }) => U) => (r: T) => U; + a9 = b9; // ok + b9 = a9; // ok + ~~ +!!! error TS2322: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U'. +!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type '{ foo: string; bing: number; }'. +!!! error TS2322: Property 'bing' is missing in type 'Base'. + var b10: (...x: T[]) => T; + a10 = b10; // ok + b10 = a10; // ok + var b11: (x: T, y: T) => T; + a11 = b11; // ok + b11 = a11; // ok + var b12: >(x: Array, y: T) => Array; + a12 = b12; // ok + b12 = a12; // ok + var b13: >(x: Array, y: T) => T; + a13 = b13; // ok + b13 = a13; // ok + var b14: (x: { a: T; b: T }) => T; + a14 = b14; // ok + b14 = a14; // ok + var b15: (x: T) => T[]; + a15 = b15; // ok + b15 = a15; // ok + var b16: (x: T) => number[]; + a16 = b16; // ok + b16 = a16; // ok + var b17: (x: (a: T) => T) => T[]; // ok + a17 = b17; // ok + b17 = a17; // ok + var b18: (x: (a: T) => T) => T[]; + a18 = b18; // ok + b18 = a18; // ok + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt index 8d184edc085..df391b27f98 100644 --- a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt @@ -1,17 +1,15 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(52,9): error TS2322: Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type '{ foo: number; }' is not assignable to type 'Base'. - Types of property 'foo' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type '{ foo: number; }' is not assignable to type 'Base'. + Types of property 'foo' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(53,9): error TS2322: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type 'Base' is not assignable to type '{ foo: number; }'. - Types of property 'foo' are incompatible. - Type 'string' is not assignable to type 'number'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type 'Base' is not assignable to type '{ foo: number; }'. + Types of property 'foo' are incompatible. + Type 'string' is not assignable to type 'number'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts (2 errors) ==== @@ -70,20 +68,18 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme ~~ !!! error TS2322: Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. !!! error TS2322: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2322: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. -!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2322: Type '{ foo: number; }' is not assignable to type 'Base'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string'. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type '{ foo: number; }' is not assignable to type 'Base'. +!!! error TS2322: Types of property 'foo' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. b8 = a8; // error, { foo: number } and Base are incompatible ~~ !!! error TS2322: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. !!! error TS2322: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2322: Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived'. -!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2322: Type 'Base' is not assignable to type '{ foo: number; }'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type '{ foo: number; }'. +!!! error TS2322: Types of property 'foo' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. var b10: (...x: T[]) => T; diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt new file mode 100644 index 00000000000..995a9b67ccd --- /dev/null +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt @@ -0,0 +1,113 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(71,1): error TS2322: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U'. + Types of parameters 'y' and 'y' are incompatible. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type 'Base' is not assignable to type '{ foo: string; bing: number; }'. + Property 'bing' is missing in type 'Base'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts (1 errors) ==== + // checking assignment compatibility relations for function types. All of these are valid. + + class Base { foo: string; } + class Derived extends Base { bar: string; } + class Derived2 extends Derived { baz: string; } + class OtherDerived extends Base { bing: string; } + + var a: new (x: number) => number[]; + var a2: new (x: number) => string[]; + var a3: new (x: number) => void; + var a4: new (x: string, y: number) => string; + var a5: new (x: (arg: string) => number) => string; + var a6: new (x: (arg: Base) => Derived) => Base; + var a7: new (x: (arg: Base) => Derived) => (r: Base) => Derived; + var a8: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; + var a9: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; + var a10: new (...x: Derived[]) => Derived; + var a11: new (x: { foo: string }, y: { foo: string; bar: string }) => Base; + var a12: new (x: Array, y: Array) => Array; + var a13: new (x: Array, y: Array) => Array; + var a14: new (x: { a: string; b: number }) => Object; + var a15: { + new (x: number): number[]; + new (x: string): string[]; + } + var a16: { + new (x: T): number[]; + new (x: U): number[]; + } + var a17: { + new (x: new (a: number) => number): number[]; + new (x: new (a: string) => string): string[]; + }; + var a18: { + new (x: { + new (a: number): number; + new (a: string): string; + }): any[]; + new (x: { + new (a: boolean): boolean; + new (a: Date): Date; + }): any[]; + } + + var b: new (x: T) => T[]; + a = b; // ok + b = a; // ok + var b2: new (x: T) => string[]; + a2 = b2; // ok + b2 = a2; // ok + var b3: new (x: T) => T; + a3 = b3; // ok + b3 = a3; // ok + var b4: new (x: T, y: U) => T; + a4 = b4; // ok + b4 = a4; // ok + var b5: new (x: (arg: T) => U) => T; + a5 = b5; // ok + b5 = a5; // ok + var b6: new (x: (arg: T) => U) => T; + a6 = b6; // ok + b6 = a6; // ok + var b7: new (x: (arg: T) => U) => (r: T) => U; + a7 = b7; // ok + b7 = a7; // ok + var b8: new (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; + a8 = b8; // ok + b8 = a8; // ok + var b9: new (x: (arg: T) => U, y: (arg2: { foo: string; bing: number }) => U) => (r: T) => U; + a9 = b9; // ok + b9 = a9; // ok + ~~ +!!! error TS2322: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U'. +!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type '{ foo: string; bing: number; }'. +!!! error TS2322: Property 'bing' is missing in type 'Base'. + var b10: new (...x: T[]) => T; + a10 = b10; // ok + b10 = a10; // ok + var b11: new (x: T, y: T) => T; + a11 = b11; // ok + b11 = a11; // ok + var b12: new >(x: Array, y: T) => Array; + a12 = b12; // ok + b12 = a12; // ok + var b13: new >(x: Array, y: T) => T; + a13 = b13; // ok + b13 = a13; // ok + var b14: new (x: { a: T; b: T }) => T; + a14 = b14; // ok + b14 = a14; // ok + var b15: new (x: T) => T[]; + a15 = b15; // ok + b15 = a15; // ok + var b16: new (x: T) => number[]; + a16 = b16; // ok + b16 = a16; // ok + var b17: new (x: new (a: T) => T) => T[]; // ok + a17 = b17; // ok + b17 = a17; // ok + var b18: new (x: new (a: T) => T) => T[]; + a18 = b18; // ok + b18 = a18; // ok + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt index f6e93e13f04..6b2f4a0de17 100644 --- a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt @@ -1,17 +1,15 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(52,9): error TS2322: Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type '{ foo: number; }' is not assignable to type 'Base'. - Types of property 'foo' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type '{ foo: number; }' is not assignable to type 'Base'. + Types of property 'foo' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(53,9): error TS2322: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type 'Base' is not assignable to type '{ foo: number; }'. - Types of property 'foo' are incompatible. - Type 'string' is not assignable to type 'number'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type 'Base' is not assignable to type '{ foo: number; }'. + Types of property 'foo' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(77,9): error TS2322: Type 'new (x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }'. Types of parameters 'x' and 'x' are incompatible. Type '{ new (a: number): number; new (a?: number): number; }' is not assignable to type '(a: any) => any'. @@ -86,20 +84,18 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme ~~ !!! error TS2322: Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. !!! error TS2322: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2322: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. -!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2322: Type '{ foo: number; }' is not assignable to type 'Base'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string'. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type '{ foo: number; }' is not assignable to type 'Base'. +!!! error TS2322: Types of property 'foo' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. b8 = a8; // error ~~ !!! error TS2322: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. !!! error TS2322: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2322: Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived'. -!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2322: Type 'Base' is not assignable to type '{ foo: number; }'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type '{ foo: number; }'. +!!! error TS2322: Types of property 'foo' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. var b10: new (...x: T[]) => T; diff --git a/tests/baselines/reference/assignmentToExpandingArrayType.js b/tests/baselines/reference/assignmentToExpandingArrayType.js new file mode 100644 index 00000000000..5b885b6913f --- /dev/null +++ b/tests/baselines/reference/assignmentToExpandingArrayType.js @@ -0,0 +1,56 @@ +//// [assignmentToExpandingArrayType.ts] +// Fixes exponential time/space in #14628 +let x = [] +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } // previously ran out of memory here +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } + + +//// [assignmentToExpandingArrayType.js] +// Fixes exponential time/space in #14628 +var x = []; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; // previously ran out of memory here +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; +x[0] = { foo: 'hi' }; diff --git a/tests/baselines/reference/assignmentToExpandingArrayType.symbols b/tests/baselines/reference/assignmentToExpandingArrayType.symbols new file mode 100644 index 00000000000..c8285706f6e --- /dev/null +++ b/tests/baselines/reference/assignmentToExpandingArrayType.symbols @@ -0,0 +1,101 @@ +=== tests/cases/compiler/assignmentToExpandingArrayType.ts === +// Fixes exponential time/space in #14628 +let x = [] +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 2, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 3, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 4, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 5, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 6, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 7, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 8, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 9, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 10, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 11, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 12, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 13, 8)) + +x[0] = { foo: 'hi' } // previously ran out of memory here +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 14, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 15, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 16, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 17, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 18, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 19, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 20, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 21, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 22, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 23, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 24, 8)) + +x[0] = { foo: 'hi' } +>x : Symbol(x, Decl(assignmentToExpandingArrayType.ts, 1, 3)) +>foo : Symbol(foo, Decl(assignmentToExpandingArrayType.ts, 25, 8)) + diff --git a/tests/baselines/reference/assignmentToExpandingArrayType.types b/tests/baselines/reference/assignmentToExpandingArrayType.types new file mode 100644 index 00000000000..da923b23646 --- /dev/null +++ b/tests/baselines/reference/assignmentToExpandingArrayType.types @@ -0,0 +1,222 @@ +=== tests/cases/compiler/assignmentToExpandingArrayType.ts === +// Fixes exponential time/space in #14628 +let x = [] +>x : any[] +>[] : undefined[] + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } // previously ran out of memory here +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + +x[0] = { foo: 'hi' } +>x[0] = { foo: 'hi' } : { foo: string; } +>x[0] : any +>x : any[] +>0 : 0 +>{ foo: 'hi' } : { foo: string; } +>foo : string +>'hi' : "hi" + diff --git a/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt b/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt index 2d7e795d26a..f5e05567b25 100644 --- a/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt +++ b/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt @@ -7,11 +7,10 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign Types of property 'a8' are incompatible. Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type '{ foo: number; }' is not assignable to type 'Base'. - Types of property 'foo' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type '{ foo: number; }' is not assignable to type 'Base'. + Types of property 'foo' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts (2 errors) ==== @@ -86,11 +85,10 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign !!! error TS2430: Types of property 'a8' are incompatible. !!! error TS2430: Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. !!! error TS2430: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2430: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. -!!! error TS2430: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2430: Type '{ foo: number; }' is not assignable to type 'Base'. -!!! error TS2430: Types of property 'foo' are incompatible. -!!! error TS2430: Type 'number' is not assignable to type 'string'. +!!! error TS2430: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2430: Type '{ foo: number; }' is not assignable to type 'Base'. +!!! error TS2430: Types of property 'foo' are incompatible. +!!! error TS2430: Type 'number' is not assignable to type 'string'. a8: (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; // error, type mismatch } diff --git a/tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt b/tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt new file mode 100644 index 00000000000..758b295a49d --- /dev/null +++ b/tests/baselines/reference/checkJsFiles_noErrorLocation.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/a.js(14,5): error TS2424: Class 'A' defines instance member function 'foo', but extended class 'B' defines it as instance member property. + + +==== tests/cases/compiler/a.js (1 errors) ==== + // @ts-check + class A { + constructor() { + + } + foo() { + return 4; + } + } + + class B extends A { + constructor() { + super(); + this.foo = () => 3; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2424: Class 'A' defines instance member function 'foo', but extended class 'B' defines it as instance member property. + } + } + + const i = new B(); + i.foo(); \ No newline at end of file diff --git a/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt b/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt index 086372aac17..7bd76159391 100644 --- a/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt +++ b/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt @@ -7,11 +7,10 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/construc Types of property 'a8' are incompatible. Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type '{ foo: number; }' is not assignable to type 'Base'. - Types of property 'foo' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type '{ foo: number; }' is not assignable to type 'Base'. + Types of property 'foo' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts (2 errors) ==== @@ -76,11 +75,10 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/construc !!! error TS2430: Types of property 'a8' are incompatible. !!! error TS2430: Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. !!! error TS2430: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2430: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. -!!! error TS2430: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2430: Type '{ foo: number; }' is not assignable to type 'Base'. -!!! error TS2430: Types of property 'foo' are incompatible. -!!! error TS2430: Type 'number' is not assignable to type 'string'. +!!! error TS2430: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2430: Type '{ foo: number; }' is not assignable to type 'Base'. +!!! error TS2430: Types of property 'foo' are incompatible. +!!! error TS2430: Type 'number' is not assignable to type 'string'. a8: new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; // error, type mismatch } diff --git a/tests/baselines/reference/covariantCallbacks.errors.txt b/tests/baselines/reference/covariantCallbacks.errors.txt new file mode 100644 index 00000000000..55c69c89728 --- /dev/null +++ b/tests/baselines/reference/covariantCallbacks.errors.txt @@ -0,0 +1,132 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(12,5): error TS2322: Type 'P' is not assignable to type 'P'. + Type 'A' is not assignable to type 'B'. + Property 'b' is missing in type 'A'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(17,5): error TS2322: Type 'Promise' is not assignable to type 'Promise'. + Type 'A' is not assignable to type 'B'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(30,5): error TS2322: Type 'AList1' is not assignable to type 'BList1'. + Types of property 'forEach' are incompatible. + Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: B) => void) => void'. + Types of parameters 'cb' and 'cb' are incompatible. + Types of parameters 'item' and 'item' are incompatible. + Type 'A' is not assignable to type 'B'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(43,5): error TS2322: Type 'AList2' is not assignable to type 'BList2'. + Types of property 'forEach' are incompatible. + Type '(cb: (item: A) => boolean) => void' is not assignable to type '(cb: (item: A) => void) => void'. + Types of parameters 'cb' and 'cb' are incompatible. + Type 'void' is not assignable to type 'boolean'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(56,5): error TS2322: Type 'AList3' is not assignable to type 'BList3'. + Types of property 'forEach' are incompatible. + Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: A, context: any) => void) => void'. + Types of parameters 'cb' and 'cb' are incompatible. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(69,5): error TS2322: Type 'AList4' is not assignable to type 'BList4'. + Types of property 'forEach' are incompatible. + Type '(cb: (item: A) => A) => void' is not assignable to type '(cb: (item: B) => B) => void'. + Types of parameters 'cb' and 'cb' are incompatible. + Types of parameters 'item' and 'item' are incompatible. + Type 'A' is not assignable to type 'B'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts (6 errors) ==== + // Test that callback parameters are related covariantly + + interface P { + then(cb: (value: T) => void): void; + }; + + interface A { a: string } + interface B extends A { b: string } + + function f1(a: P, b: P) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'P' is not assignable to type 'P'. +!!! error TS2322: Type 'A' is not assignable to type 'B'. +!!! error TS2322: Property 'b' is missing in type 'A'. + } + + function f2(a: Promise, b: Promise) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2322: Type 'A' is not assignable to type 'B'. + } + + interface AList1 { + forEach(cb: (item: A) => void): void; + } + + interface BList1 { + forEach(cb: (item: B) => void): void; + } + + function f11(a: AList1, b: BList1) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'AList1' is not assignable to type 'BList1'. +!!! error TS2322: Types of property 'forEach' are incompatible. +!!! error TS2322: Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: B) => void) => void'. +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. +!!! error TS2322: Types of parameters 'item' and 'item' are incompatible. +!!! error TS2322: Type 'A' is not assignable to type 'B'. + } + + interface AList2 { + forEach(cb: (item: A) => boolean): void; + } + + interface BList2 { + forEach(cb: (item: A) => void): void; + } + + function f12(a: AList2, b: BList2) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'AList2' is not assignable to type 'BList2'. +!!! error TS2322: Types of property 'forEach' are incompatible. +!!! error TS2322: Type '(cb: (item: A) => boolean) => void' is not assignable to type '(cb: (item: A) => void) => void'. +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. +!!! error TS2322: Type 'void' is not assignable to type 'boolean'. + } + + interface AList3 { + forEach(cb: (item: A) => void): void; + } + + interface BList3 { + forEach(cb: (item: A, context: any) => void): void; + } + + function f13(a: AList3, b: BList3) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'AList3' is not assignable to type 'BList3'. +!!! error TS2322: Types of property 'forEach' are incompatible. +!!! error TS2322: Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: A, context: any) => void) => void'. +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. + } + + interface AList4 { + forEach(cb: (item: A) => A): void; + } + + interface BList4 { + forEach(cb: (item: B) => B): void; + } + + function f14(a: AList4, b: BList4) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'AList4' is not assignable to type 'BList4'. +!!! error TS2322: Types of property 'forEach' are incompatible. +!!! error TS2322: Type '(cb: (item: A) => A) => void' is not assignable to type '(cb: (item: B) => B) => void'. +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. +!!! error TS2322: Types of parameters 'item' and 'item' are incompatible. +!!! error TS2322: Type 'A' is not assignable to type 'B'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/covariantCallbacks.js b/tests/baselines/reference/covariantCallbacks.js new file mode 100644 index 00000000000..4678c13bf15 --- /dev/null +++ b/tests/baselines/reference/covariantCallbacks.js @@ -0,0 +1,101 @@ +//// [covariantCallbacks.ts] +// Test that callback parameters are related covariantly + +interface P { + then(cb: (value: T) => void): void; +}; + +interface A { a: string } +interface B extends A { b: string } + +function f1(a: P, b: P) { + a = b; + b = a; // Error +} + +function f2(a: Promise, b: Promise) { + a = b; + b = a; // Error +} + +interface AList1 { + forEach(cb: (item: A) => void): void; +} + +interface BList1 { + forEach(cb: (item: B) => void): void; +} + +function f11(a: AList1, b: BList1) { + a = b; + b = a; // Error +} + +interface AList2 { + forEach(cb: (item: A) => boolean): void; +} + +interface BList2 { + forEach(cb: (item: A) => void): void; +} + +function f12(a: AList2, b: BList2) { + a = b; + b = a; // Error +} + +interface AList3 { + forEach(cb: (item: A) => void): void; +} + +interface BList3 { + forEach(cb: (item: A, context: any) => void): void; +} + +function f13(a: AList3, b: BList3) { + a = b; + b = a; // Error +} + +interface AList4 { + forEach(cb: (item: A) => A): void; +} + +interface BList4 { + forEach(cb: (item: B) => B): void; +} + +function f14(a: AList4, b: BList4) { + a = b; + b = a; // Error +} + + +//// [covariantCallbacks.js] +"use strict"; +// Test that callback parameters are related covariantly +; +function f1(a, b) { + a = b; + b = a; // Error +} +function f2(a, b) { + a = b; + b = a; // Error +} +function f11(a, b) { + a = b; + b = a; // Error +} +function f12(a, b) { + a = b; + b = a; // Error +} +function f13(a, b) { + a = b; + b = a; // Error +} +function f14(a, b) { + a = b; + b = a; // Error +} diff --git a/tests/baselines/reference/exportBinding.js b/tests/baselines/reference/exportBinding.js new file mode 100644 index 00000000000..5059c5356a3 --- /dev/null +++ b/tests/baselines/reference/exportBinding.js @@ -0,0 +1,19 @@ +//// [exportBinding.ts] +export { x } +const x = 'x' + +export { Y as Z } +class Y {} + + +//// [exportBinding.js] +"use strict"; +exports.__esModule = true; +var x = 'x'; +exports.x = x; +var Y = (function () { + function Y() { + } + return Y; +}()); +exports.Z = Y; diff --git a/tests/baselines/reference/exportBinding.symbols b/tests/baselines/reference/exportBinding.symbols new file mode 100644 index 00000000000..cb3b58a5776 --- /dev/null +++ b/tests/baselines/reference/exportBinding.symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/modules/exportBinding.ts === +export { x } +>x : Symbol(x, Decl(exportBinding.ts, 0, 8)) + +const x = 'x' +>x : Symbol(x, Decl(exportBinding.ts, 1, 5)) + +export { Y as Z } +>Y : Symbol(Z, Decl(exportBinding.ts, 3, 8)) +>Z : Symbol(Z, Decl(exportBinding.ts, 3, 8)) + +class Y {} +>Y : Symbol(Y, Decl(exportBinding.ts, 3, 17)) + diff --git a/tests/baselines/reference/exportBinding.types b/tests/baselines/reference/exportBinding.types new file mode 100644 index 00000000000..e2553ba1eaa --- /dev/null +++ b/tests/baselines/reference/exportBinding.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es6/modules/exportBinding.ts === +export { x } +>x : "x" + +const x = 'x' +>x : "x" +>'x' : "x" + +export { Y as Z } +>Y : typeof Y +>Z : typeof Y + +class Y {} +>Y : Y + diff --git a/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.symbols b/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.symbols new file mode 100644 index 00000000000..6cb2e235ce2 --- /dev/null +++ b/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/foo.js === +module.exports = function () { +>module : Symbol(export=, Decl(foo.js, 0, 0)) +>exports : Symbol(export=, Decl(foo.js, 0, 0)) + + class A { } +>A : Symbol(A, Decl(foo.js, 0, 30)) + + return { + c: A.b = 1, +>c : Symbol(c, Decl(foo.js, 2, 10)) +>A : Symbol(A, Decl(foo.js, 0, 30)) + } +}; + diff --git a/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.types b/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.types new file mode 100644 index 00000000000..fc1fad7f861 --- /dev/null +++ b/tests/baselines/reference/jsFileClassPropertyInitalizationInObjectLiteral.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/foo.js === +module.exports = function () { +>module.exports = function () { class A { } return { c: A.b = 1, }} : () => { [x: string]: any; c: number; } +>module.exports : any +>module : any +>exports : any +>function () { class A { } return { c: A.b = 1, }} : () => { [x: string]: any; c: number; } + + class A { } +>A : A + + return { +>{ c: A.b = 1, } : { [x: string]: any; c: number; } + + c: A.b = 1, +>c : number +>A.b = 1 : 1 +>A.b : any +>A : typeof A +>b : any +>1 : 1 + } +}; + diff --git a/tests/baselines/reference/library-reference-scoped-packages.js b/tests/baselines/reference/library-reference-scoped-packages.js new file mode 100644 index 00000000000..3019008c16b --- /dev/null +++ b/tests/baselines/reference/library-reference-scoped-packages.js @@ -0,0 +1,11 @@ +//// [tests/cases/conformance/references/library-reference-scoped-packages.ts] //// + +//// [index.d.ts] +export const y = 0; + +//// [a.ts] +/// + + +//// [a.js] +/// diff --git a/tests/baselines/reference/library-reference-scoped-packages.symbols b/tests/baselines/reference/library-reference-scoped-packages.symbols new file mode 100644 index 00000000000..60ccaab89d2 --- /dev/null +++ b/tests/baselines/reference/library-reference-scoped-packages.symbols @@ -0,0 +1,7 @@ +=== /a.ts === +/// +No type information for this code. +No type information for this code.=== /node_modules/@types/beep__boop/index.d.ts === +export const y = 0; +>y : Symbol(y, Decl(index.d.ts, 0, 12)) + diff --git a/tests/baselines/reference/library-reference-scoped-packages.trace.json b/tests/baselines/reference/library-reference-scoped-packages.trace.json new file mode 100644 index 00000000000..54dcf95fe50 --- /dev/null +++ b/tests/baselines/reference/library-reference-scoped-packages.trace.json @@ -0,0 +1,12 @@ +[ + "======== Resolving type reference directive '@beep/boop', containing file '/a.ts', root directory 'types'. ========", + "Resolving with primary search path 'types'.", + "Directory 'types/@beep' does not exist, skipping all lookups in it.", + "Looking up in 'node_modules' folder, initial location '/'.", + "Scoped package detected, looking in 'beep__boop'", + "File '/node_modules/@types/beep__boop.d.ts' does not exist.", + "File '/node_modules/@types/beep__boop/package.json' does not exist.", + "File '/node_modules/@types/beep__boop/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/beep__boop/index.d.ts', result '/node_modules/@types/beep__boop/index.d.ts'.", + "======== Type reference directive '@beep/boop' was successfully resolved to '/node_modules/@types/beep__boop/index.d.ts', primary: false. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-scoped-packages.types b/tests/baselines/reference/library-reference-scoped-packages.types new file mode 100644 index 00000000000..bbb3062d98b --- /dev/null +++ b/tests/baselines/reference/library-reference-scoped-packages.types @@ -0,0 +1,8 @@ +=== /a.ts === +/// +No type information for this code. +No type information for this code.=== /node_modules/@types/beep__boop/index.d.ts === +export const y = 0; +>y : 0 +>0 : 0 + diff --git a/tests/baselines/reference/optionalFunctionArgAssignability.errors.txt b/tests/baselines/reference/optionalFunctionArgAssignability.errors.txt index 024c5c1ea2b..1898db92463 100644 --- a/tests/baselines/reference/optionalFunctionArgAssignability.errors.txt +++ b/tests/baselines/reference/optionalFunctionArgAssignability.errors.txt @@ -1,8 +1,7 @@ tests/cases/compiler/optionalFunctionArgAssignability.ts(7,1): error TS2322: Type '(onFulFill?: (value: number) => U, onReject?: (reason: any) => U) => Promise' is not assignable to type '(onFulfill?: (value: string) => U, onReject?: (reason: any) => U) => Promise'. Types of parameters 'onFulFill' and 'onFulfill' are incompatible. - Type '(value: string) => any' is not assignable to type '(value: number) => any'. - Types of parameters 'value' and 'value' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'value' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/optionalFunctionArgAssignability.ts (1 errors) ==== @@ -16,7 +15,6 @@ tests/cases/compiler/optionalFunctionArgAssignability.ts(7,1): error TS2322: Typ ~ !!! error TS2322: Type '(onFulFill?: (value: number) => U, onReject?: (reason: any) => U) => Promise' is not assignable to type '(onFulfill?: (value: string) => U, onReject?: (reason: any) => U) => Promise'. !!! error TS2322: Types of parameters 'onFulFill' and 'onFulfill' are incompatible. -!!! error TS2322: Type '(value: string) => any' is not assignable to type '(value: number) => any'. -!!! error TS2322: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string'. +!!! error TS2322: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt b/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt index 0573c6ed79e..aa7bbf77239 100644 --- a/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt +++ b/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt @@ -1,8 +1,11 @@ +tests/cases/compiler/overloadOnConstNoAnyImplementation.ts(1,10): error TS2394: Overload signature is not compatible with function implementation. tests/cases/compiler/overloadOnConstNoAnyImplementation.ts(9,8): error TS2345: Argument of type '1' is not assignable to parameter of type 'string'. -==== tests/cases/compiler/overloadOnConstNoAnyImplementation.ts (1 errors) ==== +==== tests/cases/compiler/overloadOnConstNoAnyImplementation.ts (2 errors) ==== function x1(a: number, cb: (x: 'hi') => number); + ~~ +!!! error TS2394: Overload signature is not compatible with function implementation. function x1(a: number, cb: (x: 'bye') => number); function x1(a: number, cb: (x: string) => number) { cb('hi'); diff --git a/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt b/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt index 24047578ec6..a090f370863 100644 --- a/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt +++ b/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(6,5): error TS2394: Overload signature is not compatible with function implementation. tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(12,18): error TS2345: Argument of type '1' is not assignable to parameter of type 'string'. tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(18,9): error TS2345: Argument of type '(x: "bye") => number' is not assignable to parameter of type '(x: "hi") => number'. Types of parameters 'x' and 'x' are incompatible. @@ -7,13 +8,15 @@ tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(21,9): error TS2345: Type '"hi"' is not assignable to type 'number'. -==== tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts (3 errors) ==== +==== tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts (4 errors) ==== interface I { x1(a: number, callback: (x: 'hi') => number); } class C { x1(a: number, callback: (x: 'hi') => number); + ~~ +!!! error TS2394: Overload signature is not compatible with function implementation. x1(a: number, callback: (x: string) => number) { callback('hi'); callback('bye'); diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index e5e7f2109a9..8b46f18666f 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -31,16 +31,16 @@ tests/cases/compiler/promisePermutations.ts(110,19): error TS2345: Argument of t tests/cases/compiler/promisePermutations.ts(111,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. -tests/cases/compiler/promisePermutations.ts(117,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations.ts(117,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations.ts(122,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations.ts(126,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(126,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(129,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/promisePermutations.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations.ts(134,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(137,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. @@ -51,9 +51,8 @@ tests/cases/compiler/promisePermutations.ts(152,12): error TS2453: The type argu Types of property 'then' are incompatible. Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. Types of parameters 'success' and 'onfulfilled' are incompatible. - Type '(value: number) => any' is not assignable to type '(value: string) => IPromise'. - Types of parameters 'value' and 'value' are incompatible. - Type 'string' is not assignable to type 'number'. + Types of parameters 'value' and 'value' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations.ts(156,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. Type 'IPromise' is not assignable to type 'IPromise'. Type 'number' is not assignable to type 'string'. @@ -67,9 +66,8 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t Types of property 'then' are incompatible. Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. Types of parameters 'onfulfilled' and 'success' are incompatible. - Type '(value: string) => IPromise' is not assignable to type '(value: number) => any'. - Types of parameters 'value' and 'value' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'value' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/promisePermutations.ts (33 errors) ==== @@ -241,15 +239,15 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var nPromise: (x: any) => Promise; var r8a = r8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r8b = r8.then(nIPromise, nIPromise, nIPromise).then(nIPromise, nIPromise, nIPromise); // ok var s8: Promise; var s8a = s8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s8b = s8.then(testFunction8P, testFunction8P, testFunction8P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s8c = s8.then(testFunction8P, testFunction8, testFunction8); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -258,7 +256,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok @@ -270,10 +268,10 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -307,9 +305,8 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t !!! error TS2453: Types of property 'then' are incompatible. !!! error TS2453: Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. !!! error TS2453: Types of parameters 'success' and 'onfulfilled' are incompatible. -!!! error TS2453: Type '(value: number) => any' is not assignable to type '(value: string) => IPromise'. -!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2453: Type 'string' is not assignable to type 'number'. +!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2453: Type 'string' is not assignable to type 'number'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -335,9 +332,8 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t !!! error TS2345: Types of property 'then' are incompatible. !!! error TS2345: Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. !!! error TS2345: Types of parameters 'onfulfilled' and 'success' are incompatible. -!!! error TS2345: Type '(value: string) => IPromise' is not assignable to type '(value: number) => any'. -!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2345: Type 'number' is not assignable to type 'string'. +!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index 26fec6b2fd1..32df80e20f1 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -31,16 +31,16 @@ tests/cases/compiler/promisePermutations2.ts(109,19): error TS2345: Argument of tests/cases/compiler/promisePermutations2.ts(110,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. -tests/cases/compiler/promisePermutations2.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations2.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations2.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations2.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations2.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(128,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/promisePermutations2.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations2.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations2.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(136,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. @@ -51,9 +51,8 @@ tests/cases/compiler/promisePermutations2.ts(151,12): error TS2453: The type arg Types of property 'then' are incompatible. Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. Types of parameters 'success' and 'onfulfilled' are incompatible. - Type '(value: number) => any' is not assignable to type '(value: string) => IPromise'. - Types of parameters 'value' and 'value' are incompatible. - Type 'string' is not assignable to type 'number'. + Types of parameters 'value' and 'value' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations2.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. Type 'IPromise' is not assignable to type 'IPromise'. Type 'number' is not assignable to type 'string'. @@ -67,9 +66,8 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of Types of property 'then' are incompatible. Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. Types of parameters 'onfulfilled' and 'success' are incompatible. - Type '(value: string) => IPromise' is not assignable to type '(value: number) => any'. - Types of parameters 'value' and 'value' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'value' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/promisePermutations2.ts (33 errors) ==== @@ -240,15 +238,15 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var nPromise: (x: any) => Promise; var r8a = r8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r8b = r8.then(nIPromise, nIPromise, nIPromise).then(nIPromise, nIPromise, nIPromise); // ok var s8: Promise; var s8a = s8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s8b = s8.then(testFunction8P, testFunction8P, testFunction8P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s8c = s8.then(testFunction8P, testFunction8, testFunction8); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -257,7 +255,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // error @@ -269,10 +267,10 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -306,9 +304,8 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of !!! error TS2453: Types of property 'then' are incompatible. !!! error TS2453: Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. !!! error TS2453: Types of parameters 'success' and 'onfulfilled' are incompatible. -!!! error TS2453: Type '(value: number) => any' is not assignable to type '(value: string) => IPromise'. -!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2453: Type 'string' is not assignable to type 'number'. +!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2453: Type 'string' is not assignable to type 'number'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -334,9 +331,8 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of !!! error TS2345: Types of property 'then' are incompatible. !!! error TS2345: Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. !!! error TS2345: Types of parameters 'onfulfilled' and 'success' are incompatible. -!!! error TS2345: Type '(value: string) => IPromise' is not assignable to type '(value: number) => any'. -!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2345: Type 'number' is not assignable to type 'string'. +!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index 1354f486fcb..3d9fc1b2d26 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -34,16 +34,16 @@ tests/cases/compiler/promisePermutations3.ts(109,19): error TS2345: Argument of tests/cases/compiler/promisePermutations3.ts(110,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. -tests/cases/compiler/promisePermutations3.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations3.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations3.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations3.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations3.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations3.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(128,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/promisePermutations3.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations3.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations3.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations3.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(136,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'IPromise' is not a valid type argument because it is not a supertype of candidate 'IPromise'. @@ -54,9 +54,8 @@ tests/cases/compiler/promisePermutations3.ts(151,12): error TS2453: The type arg Types of property 'then' are incompatible. Type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. Types of parameters 'success' and 'onfulfilled' are incompatible. - Type '(value: number) => any' is not assignable to type '(value: string) => any'. - Types of parameters 'value' and 'value' are incompatible. - Type 'string' is not assignable to type 'number'. + Types of parameters 'value' and 'value' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations3.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. Type 'IPromise' is not assignable to type 'IPromise'. Type 'number' is not assignable to type 'string'. @@ -70,9 +69,8 @@ tests/cases/compiler/promisePermutations3.ts(159,21): error TS2345: Argument of Types of property 'then' are incompatible. Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise'. Types of parameters 'onfulfilled' and 'success' are incompatible. - Type '(value: string) => any' is not assignable to type '(value: number) => any'. - Types of parameters 'value' and 'value' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'value' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. Type 'IPromise' is not assignable to type 'Promise'. Types of property 'then' are incompatible. @@ -252,15 +250,15 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var nPromise: (x: any) => Promise; var r8a = r8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r8b = r8.then(nIPromise, nIPromise, nIPromise).then(nIPromise, nIPromise, nIPromise); // ok var s8: Promise; var s8a = s8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s8b = s8.then(testFunction8P, testFunction8P, testFunction8P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s8c = s8.then(testFunction8P, testFunction8, testFunction8); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -269,7 +267,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // error @@ -281,10 +279,10 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -318,9 +316,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2453: Types of property 'then' are incompatible. !!! error TS2453: Type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. !!! error TS2453: Types of parameters 'success' and 'onfulfilled' are incompatible. -!!! error TS2453: Type '(value: number) => any' is not assignable to type '(value: string) => any'. -!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2453: Type 'string' is not assignable to type 'number'. +!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2453: Type 'string' is not assignable to type 'number'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -346,9 +343,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2345: Types of property 'then' are incompatible. !!! error TS2345: Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise'. !!! error TS2345: Types of parameters 'onfulfilled' and 'success' are incompatible. -!!! error TS2345: Type '(value: string) => any' is not assignable to type '(value: number) => any'. -!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2345: Type 'number' is not assignable to type 'string'. +!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisesWithConstraints.errors.txt b/tests/baselines/reference/promisesWithConstraints.errors.txt new file mode 100644 index 00000000000..d2c459da284 --- /dev/null +++ b/tests/baselines/reference/promisesWithConstraints.errors.txt @@ -0,0 +1,36 @@ +tests/cases/compiler/promisesWithConstraints.ts(15,1): error TS2322: Type 'Promise' is not assignable to type 'Promise'. + Type 'Foo' is not assignable to type 'Bar'. + Property 'y' is missing in type 'Foo'. +tests/cases/compiler/promisesWithConstraints.ts(20,1): error TS2322: Type 'CPromise' is not assignable to type 'CPromise'. + Type 'Foo' is not assignable to type 'Bar'. + + +==== tests/cases/compiler/promisesWithConstraints.ts (2 errors) ==== + interface Promise { + then(cb: (x: T) => Promise): Promise; + } + + interface CPromise { + then(cb: (x: T) => Promise): Promise; + } + + interface Foo { x; } + interface Bar { x; y; } + + var a: Promise; + var b: Promise; + a = b; // ok + b = a; // ok + ~ +!!! error TS2322: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2322: Type 'Foo' is not assignable to type 'Bar'. +!!! error TS2322: Property 'y' is missing in type 'Foo'. + + var a2: CPromise; + var b2: CPromise; + a2 = b2; // ok + b2 = a2; // was error + ~~ +!!! error TS2322: Type 'CPromise' is not assignable to type 'CPromise'. +!!! error TS2322: Type 'Foo' is not assignable to type 'Bar'. + \ No newline at end of file diff --git a/tests/baselines/reference/recursiveTypeComparison2.errors.txt b/tests/baselines/reference/recursiveTypeComparison2.errors.txt index 5c1200ceec6..71f337ad15f 100644 --- a/tests/baselines/reference/recursiveTypeComparison2.errors.txt +++ b/tests/baselines/reference/recursiveTypeComparison2.errors.txt @@ -1,7 +1,9 @@ tests/cases/compiler/recursiveTypeComparison2.ts(13,80): error TS2304: Cannot find name 'StateValue'. +tests/cases/compiler/recursiveTypeComparison2.ts(30,5): error TS2322: Type 'Bus<{}>' is not assignable to type 'Bus'. + Type '{}' is not assignable to type 'number'. -==== tests/cases/compiler/recursiveTypeComparison2.ts (1 errors) ==== +==== tests/cases/compiler/recursiveTypeComparison2.ts (2 errors) ==== // Before fix this would cause compiler to hang (#1170) declare module Bacon { @@ -33,4 +35,7 @@ tests/cases/compiler/recursiveTypeComparison2.ts(13,80): error TS2304: Cannot fi var Bus: new () => Bus; } - var stuck: Bacon.Bus = new Bacon.Bus(); \ No newline at end of file + var stuck: Bacon.Bus = new Bacon.Bus(); + ~~~~~ +!!! error TS2322: Type 'Bus<{}>' is not assignable to type 'Bus'. +!!! error TS2322: Type '{}' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/scopedPackages.js b/tests/baselines/reference/scopedPackages.js new file mode 100644 index 00000000000..75606d2e1b9 --- /dev/null +++ b/tests/baselines/reference/scopedPackages.js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/moduleResolution/scopedPackages.ts] //// + +//// [index.d.ts] +export const x: number; + +//// [index.d.ts] +export const y: number; + +//// [z.d.ts] +export const z: number; + +//// [a.ts] +import { x } from "@cow/boy"; +import { y } from "@be/bop"; +import { z } from "@be/bop/e/z"; + + +//// [a.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/scopedPackages.symbols b/tests/baselines/reference/scopedPackages.symbols new file mode 100644 index 00000000000..e992c4d9375 --- /dev/null +++ b/tests/baselines/reference/scopedPackages.symbols @@ -0,0 +1,22 @@ +=== /a.ts === +import { x } from "@cow/boy"; +>x : Symbol(x, Decl(a.ts, 0, 8)) + +import { y } from "@be/bop"; +>y : Symbol(y, Decl(a.ts, 1, 8)) + +import { z } from "@be/bop/e/z"; +>z : Symbol(z, Decl(a.ts, 2, 8)) + +=== /node_modules/@cow/boy/index.d.ts === +export const x: number; +>x : Symbol(x, Decl(index.d.ts, 0, 12)) + +=== /node_modules/@types/be__bop/index.d.ts === +export const y: number; +>y : Symbol(y, Decl(index.d.ts, 0, 12)) + +=== /node_modules/@types/be__bop/e/z.d.ts === +export const z: number; +>z : Symbol(z, Decl(z.d.ts, 0, 12)) + diff --git a/tests/baselines/reference/scopedPackages.trace.json b/tests/baselines/reference/scopedPackages.trace.json new file mode 100644 index 00000000000..20df3bec172 --- /dev/null +++ b/tests/baselines/reference/scopedPackages.trace.json @@ -0,0 +1,30 @@ +[ + "======== Resolving module '@cow/boy' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module '@cow/boy' from 'node_modules' folder, target file type 'TypeScript'.", + "File '/node_modules/@cow/boy.ts' does not exist.", + "File '/node_modules/@cow/boy.tsx' does not exist.", + "File '/node_modules/@cow/boy.d.ts' does not exist.", + "File '/node_modules/@cow/boy/package.json' does not exist.", + "File '/node_modules/@cow/boy/index.ts' does not exist.", + "File '/node_modules/@cow/boy/index.tsx' does not exist.", + "File '/node_modules/@cow/boy/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@cow/boy/index.d.ts', result '/node_modules/@cow/boy/index.d.ts'.", + "======== Module name '@cow/boy' was successfully resolved to '/node_modules/@cow/boy/index.d.ts'. ========", + "======== Resolving module '@be/bop' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module '@be/bop' from 'node_modules' folder, target file type 'TypeScript'.", + "Scoped package detected, looking in 'be__bop'", + "File '/node_modules/@types/be__bop.d.ts' does not exist.", + "File '/node_modules/@types/be__bop/package.json' does not exist.", + "File '/node_modules/@types/be__bop/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/be__bop/index.d.ts', result '/node_modules/@types/be__bop/index.d.ts'.", + "======== Module name '@be/bop' was successfully resolved to '/node_modules/@types/be__bop/index.d.ts'. ========", + "======== Resolving module '@be/bop/e/z' from '/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module '@be/bop/e/z' from 'node_modules' folder, target file type 'TypeScript'.", + "Scoped package detected, looking in 'be__bop/e/z'", + "File '/node_modules/@types/be__bop/e/z.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/@types/be__bop/e/z.d.ts', result '/node_modules/@types/be__bop/e/z.d.ts'.", + "======== Module name '@be/bop/e/z' was successfully resolved to '/node_modules/@types/be__bop/e/z.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/scopedPackages.types b/tests/baselines/reference/scopedPackages.types new file mode 100644 index 00000000000..c876590f54a --- /dev/null +++ b/tests/baselines/reference/scopedPackages.types @@ -0,0 +1,22 @@ +=== /a.ts === +import { x } from "@cow/boy"; +>x : number + +import { y } from "@be/bop"; +>y : number + +import { z } from "@be/bop/e/z"; +>z : number + +=== /node_modules/@cow/boy/index.d.ts === +export const x: number; +>x : number + +=== /node_modules/@types/be__bop/index.d.ts === +export const y: number; +>y : number + +=== /node_modules/@types/be__bop/e/z.d.ts === +export const z: number; +>z : number + diff --git a/tests/baselines/reference/scopedPackagesClassic.js b/tests/baselines/reference/scopedPackagesClassic.js new file mode 100644 index 00000000000..f42acde2306 --- /dev/null +++ b/tests/baselines/reference/scopedPackagesClassic.js @@ -0,0 +1,12 @@ +//// [tests/cases/conformance/moduleResolution/scopedPackagesClassic.ts] //// + +//// [index.d.ts] +export const x = 0; + +//// [a.ts] +import { x } from "@see/saw"; + + +//// [a.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/scopedPackagesClassic.symbols b/tests/baselines/reference/scopedPackagesClassic.symbols new file mode 100644 index 00000000000..e0d84f44c91 --- /dev/null +++ b/tests/baselines/reference/scopedPackagesClassic.symbols @@ -0,0 +1,8 @@ +=== /a.ts === +import { x } from "@see/saw"; +>x : Symbol(x, Decl(a.ts, 0, 8)) + +=== /node_modules/@types/see__saw/index.d.ts === +export const x = 0; +>x : Symbol(x, Decl(index.d.ts, 0, 12)) + diff --git a/tests/baselines/reference/scopedPackagesClassic.trace.json b/tests/baselines/reference/scopedPackagesClassic.trace.json new file mode 100644 index 00000000000..c58c7d2ed10 --- /dev/null +++ b/tests/baselines/reference/scopedPackagesClassic.trace.json @@ -0,0 +1,9 @@ +[ + "======== Resolving module '@see/saw' from '/a.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "Scoped package detected, looking in 'see__saw'", + "File '/node_modules/@types/see__saw.d.ts' does not exist.", + "File '/node_modules/@types/see__saw/package.json' does not exist.", + "File '/node_modules/@types/see__saw/index.d.ts' exist - use it as a name resolution result.", + "======== Module name '@see/saw' was successfully resolved to '/node_modules/@types/see__saw/index.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/scopedPackagesClassic.types b/tests/baselines/reference/scopedPackagesClassic.types new file mode 100644 index 00000000000..65047f2436d --- /dev/null +++ b/tests/baselines/reference/scopedPackagesClassic.types @@ -0,0 +1,9 @@ +=== /a.ts === +import { x } from "@see/saw"; +>x : 0 + +=== /node_modules/@types/see__saw/index.d.ts === +export const x = 0; +>x : 0 +>0 : 0 + diff --git a/tests/baselines/reference/subtypingWithCallSignatures2.types b/tests/baselines/reference/subtypingWithCallSignatures2.types index 8ce4b566b86..86c65702b98 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures2.types +++ b/tests/baselines/reference/subtypingWithCallSignatures2.types @@ -681,14 +681,14 @@ var r9 = foo9(r9arg1); // any >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U var r9a = [r9arg1, r9arg2]; ->r9a : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] ->[r9arg1, r9arg2] : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] +>r9a : (((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r9arg1, r9arg2] : (((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U >r9arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived var r9b = [r9arg2, r9arg1]; ->r9b : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] ->[r9arg2, r9arg1] : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] +>r9b : (((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r9arg2, r9arg1] : (((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] >r9arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U diff --git a/tests/baselines/reference/typeofUsedBeforeBlockScoped.js b/tests/baselines/reference/typeofUsedBeforeBlockScoped.js new file mode 100644 index 00000000000..eebf4beae67 --- /dev/null +++ b/tests/baselines/reference/typeofUsedBeforeBlockScoped.js @@ -0,0 +1,19 @@ +//// [typeofUsedBeforeBlockScoped.ts] +type T = typeof C & typeof C.s & typeof o & typeof o.n; +class C { + static s = 2; +} +type W = typeof o.n; +let o2: typeof o; +let o = { n: 12 }; + + +//// [typeofUsedBeforeBlockScoped.js] +var C = (function () { + function C() { + } + return C; +}()); +C.s = 2; +var o2; +var o = { n: 12 }; diff --git a/tests/baselines/reference/typeofUsedBeforeBlockScoped.symbols b/tests/baselines/reference/typeofUsedBeforeBlockScoped.symbols new file mode 100644 index 00000000000..5cf09a4d4d5 --- /dev/null +++ b/tests/baselines/reference/typeofUsedBeforeBlockScoped.symbols @@ -0,0 +1,32 @@ +=== tests/cases/compiler/typeofUsedBeforeBlockScoped.ts === +type T = typeof C & typeof C.s & typeof o & typeof o.n; +>T : Symbol(T, Decl(typeofUsedBeforeBlockScoped.ts, 0, 0)) +>C : Symbol(C, Decl(typeofUsedBeforeBlockScoped.ts, 0, 55)) +>C.s : Symbol(C.s, Decl(typeofUsedBeforeBlockScoped.ts, 1, 9)) +>C : Symbol(C, Decl(typeofUsedBeforeBlockScoped.ts, 0, 55)) +>s : Symbol(C.s, Decl(typeofUsedBeforeBlockScoped.ts, 1, 9)) +>o : Symbol(o, Decl(typeofUsedBeforeBlockScoped.ts, 6, 3)) +>o.n : Symbol(n, Decl(typeofUsedBeforeBlockScoped.ts, 6, 9)) +>o : Symbol(o, Decl(typeofUsedBeforeBlockScoped.ts, 6, 3)) +>n : Symbol(n, Decl(typeofUsedBeforeBlockScoped.ts, 6, 9)) + +class C { +>C : Symbol(C, Decl(typeofUsedBeforeBlockScoped.ts, 0, 55)) + + static s = 2; +>s : Symbol(C.s, Decl(typeofUsedBeforeBlockScoped.ts, 1, 9)) +} +type W = typeof o.n; +>W : Symbol(W, Decl(typeofUsedBeforeBlockScoped.ts, 3, 1)) +>o.n : Symbol(n, Decl(typeofUsedBeforeBlockScoped.ts, 6, 9)) +>o : Symbol(o, Decl(typeofUsedBeforeBlockScoped.ts, 6, 3)) +>n : Symbol(n, Decl(typeofUsedBeforeBlockScoped.ts, 6, 9)) + +let o2: typeof o; +>o2 : Symbol(o2, Decl(typeofUsedBeforeBlockScoped.ts, 5, 3)) +>o : Symbol(o, Decl(typeofUsedBeforeBlockScoped.ts, 6, 3)) + +let o = { n: 12 }; +>o : Symbol(o, Decl(typeofUsedBeforeBlockScoped.ts, 6, 3)) +>n : Symbol(n, Decl(typeofUsedBeforeBlockScoped.ts, 6, 9)) + diff --git a/tests/baselines/reference/typeofUsedBeforeBlockScoped.types b/tests/baselines/reference/typeofUsedBeforeBlockScoped.types new file mode 100644 index 00000000000..ec8e30bb135 --- /dev/null +++ b/tests/baselines/reference/typeofUsedBeforeBlockScoped.types @@ -0,0 +1,35 @@ +=== tests/cases/compiler/typeofUsedBeforeBlockScoped.ts === +type T = typeof C & typeof C.s & typeof o & typeof o.n; +>T : T +>C : typeof C +>C.s : number +>C : typeof C +>s : number +>o : { n: number; } +>o.n : number +>o : { n: number; } +>n : number + +class C { +>C : C + + static s = 2; +>s : number +>2 : 2 +} +type W = typeof o.n; +>W : number +>o.n : number +>o : { n: number; } +>n : number + +let o2: typeof o; +>o2 : { n: number; } +>o : { n: number; } + +let o = { n: 12 }; +>o : { n: number; } +>{ n: 12 } : { n: number; } +>n : number +>12 : 12 + diff --git a/tests/baselines/reference/unknownPropertiesAreAssignableToObjectUnion.js b/tests/baselines/reference/unknownPropertiesAreAssignableToObjectUnion.js new file mode 100644 index 00000000000..7140f13cb7b --- /dev/null +++ b/tests/baselines/reference/unknownPropertiesAreAssignableToObjectUnion.js @@ -0,0 +1,8 @@ +//// [unknownPropertiesAreAssignableToObjectUnion.ts] +const x: Object | string = { x: 0 }; +const y: Object | undefined = { x: 0 }; + + +//// [unknownPropertiesAreAssignableToObjectUnion.js] +var x = { x: 0 }; +var y = { x: 0 }; diff --git a/tests/baselines/reference/unknownPropertiesAreAssignableToObjectUnion.symbols b/tests/baselines/reference/unknownPropertiesAreAssignableToObjectUnion.symbols new file mode 100644 index 00000000000..f9c0b09c987 --- /dev/null +++ b/tests/baselines/reference/unknownPropertiesAreAssignableToObjectUnion.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/unknownPropertiesAreAssignableToObjectUnion.ts === +const x: Object | string = { x: 0 }; +>x : Symbol(x, Decl(unknownPropertiesAreAssignableToObjectUnion.ts, 0, 5)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(unknownPropertiesAreAssignableToObjectUnion.ts, 0, 28)) + +const y: Object | undefined = { x: 0 }; +>y : Symbol(y, Decl(unknownPropertiesAreAssignableToObjectUnion.ts, 1, 5)) +>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(unknownPropertiesAreAssignableToObjectUnion.ts, 1, 31)) + diff --git a/tests/baselines/reference/unknownPropertiesAreAssignableToObjectUnion.types b/tests/baselines/reference/unknownPropertiesAreAssignableToObjectUnion.types new file mode 100644 index 00000000000..d242cb8805c --- /dev/null +++ b/tests/baselines/reference/unknownPropertiesAreAssignableToObjectUnion.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/unknownPropertiesAreAssignableToObjectUnion.ts === +const x: Object | string = { x: 0 }; +>x : string | Object +>Object : Object +>{ x: 0 } : { x: number; } +>x : number +>0 : 0 + +const y: Object | undefined = { x: 0 }; +>y : Object | undefined +>Object : Object +>{ x: 0 } : { x: number; } +>x : number +>0 : 0 + diff --git a/tests/cases/compiler/assignmentToExpandingArrayType.ts b/tests/cases/compiler/assignmentToExpandingArrayType.ts new file mode 100644 index 00000000000..05680afa386 --- /dev/null +++ b/tests/cases/compiler/assignmentToExpandingArrayType.ts @@ -0,0 +1,27 @@ +// @noImplicitAny: true +// Fixes exponential time/space in #14628 +let x = [] +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } // previously ran out of memory here +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } +x[0] = { foo: 'hi' } diff --git a/tests/cases/compiler/checkJsFiles_noErrorLocation.ts b/tests/cases/compiler/checkJsFiles_noErrorLocation.ts new file mode 100644 index 00000000000..a0b12c47115 --- /dev/null +++ b/tests/cases/compiler/checkJsFiles_noErrorLocation.ts @@ -0,0 +1,24 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true + +// @fileName: a.js +// @ts-check +class A { + constructor() { + + } + foo() { + return 4; + } +} + +class B extends A { + constructor() { + super(); + this.foo = () => 3; + } +} + +const i = new B(); +i.foo(); \ No newline at end of file diff --git a/tests/cases/compiler/jsFileClassPropertyInitalizationInObjectLiteral.ts b/tests/cases/compiler/jsFileClassPropertyInitalizationInObjectLiteral.ts new file mode 100644 index 00000000000..d8908740fd4 --- /dev/null +++ b/tests/cases/compiler/jsFileClassPropertyInitalizationInObjectLiteral.ts @@ -0,0 +1,10 @@ +// @allowJs: true +// @noEmit: true + +// @filename: foo.js +module.exports = function () { + class A { } + return { + c: A.b = 1, + } +}; diff --git a/tests/cases/compiler/typeofUsedBeforeBlockScoped.ts b/tests/cases/compiler/typeofUsedBeforeBlockScoped.ts new file mode 100644 index 00000000000..3ab1534875b --- /dev/null +++ b/tests/cases/compiler/typeofUsedBeforeBlockScoped.ts @@ -0,0 +1,7 @@ +type T = typeof C & typeof C.s & typeof o & typeof o.n; +class C { + static s = 2; +} +type W = typeof o.n; +let o2: typeof o; +let o = { n: 12 }; diff --git a/tests/cases/compiler/unknownPropertiesAreAssignableToObjectUnion.ts b/tests/cases/compiler/unknownPropertiesAreAssignableToObjectUnion.ts new file mode 100644 index 00000000000..eb4209509de --- /dev/null +++ b/tests/cases/compiler/unknownPropertiesAreAssignableToObjectUnion.ts @@ -0,0 +1,3 @@ +// @strictNullChecks: true +const x: Object | string = { x: 0 }; +const y: Object | undefined = { x: 0 }; diff --git a/tests/cases/conformance/es6/modules/exportBinding.ts b/tests/cases/conformance/es6/modules/exportBinding.ts new file mode 100644 index 00000000000..1e6b0314f0b --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportBinding.ts @@ -0,0 +1,5 @@ +export { x } +const x = 'x' + +export { Y as Z } +class Y {} diff --git a/tests/cases/conformance/moduleResolution/scopedPackages.ts b/tests/cases/conformance/moduleResolution/scopedPackages.ts new file mode 100644 index 00000000000..b604f10d7ec --- /dev/null +++ b/tests/cases/conformance/moduleResolution/scopedPackages.ts @@ -0,0 +1,17 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @typeRoots: types + +// @filename: /node_modules/@cow/boy/index.d.ts +export const x: number; + +// @filename: /node_modules/@types/be__bop/index.d.ts +export const y: number; + +// @filename: /node_modules/@types/be__bop/e/z.d.ts +export const z: number; + +// @filename: /a.ts +import { x } from "@cow/boy"; +import { y } from "@be/bop"; +import { z } from "@be/bop/e/z"; diff --git a/tests/cases/conformance/moduleResolution/scopedPackagesClassic.ts b/tests/cases/conformance/moduleResolution/scopedPackagesClassic.ts new file mode 100644 index 00000000000..41b6fc09e19 --- /dev/null +++ b/tests/cases/conformance/moduleResolution/scopedPackagesClassic.ts @@ -0,0 +1,10 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @typeRoots: types +// @moduleResolution: classic + +// @filename: /node_modules/@types/see__saw/index.d.ts +export const x = 0; + +// @filename: /a.ts +import { x } from "@see/saw"; diff --git a/tests/cases/conformance/references/library-reference-scoped-packages.ts b/tests/cases/conformance/references/library-reference-scoped-packages.ts new file mode 100644 index 00000000000..86a1ad3e93d --- /dev/null +++ b/tests/cases/conformance/references/library-reference-scoped-packages.ts @@ -0,0 +1,9 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @typeRoots: types + +// @filename: /node_modules/@types/beep__boop/index.d.ts +export const y = 0; + +// @filename: /a.ts +/// diff --git a/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts b/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts new file mode 100644 index 00000000000..4f3e7ecda0d --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts @@ -0,0 +1,73 @@ +// @target: es2015 +// @strict: true + +// Test that callback parameters are related covariantly + +interface P { + then(cb: (value: T) => void): void; +}; + +interface A { a: string } +interface B extends A { b: string } + +function f1(a: P, b: P) { + a = b; + b = a; // Error +} + +function f2(a: Promise, b: Promise) { + a = b; + b = a; // Error +} + +interface AList1 { + forEach(cb: (item: A) => void): void; +} + +interface BList1 { + forEach(cb: (item: B) => void): void; +} + +function f11(a: AList1, b: BList1) { + a = b; + b = a; // Error +} + +interface AList2 { + forEach(cb: (item: A) => boolean): void; +} + +interface BList2 { + forEach(cb: (item: A) => void): void; +} + +function f12(a: AList2, b: BList2) { + a = b; + b = a; // Error +} + +interface AList3 { + forEach(cb: (item: A) => void): void; +} + +interface BList3 { + forEach(cb: (item: A, context: any) => void): void; +} + +function f13(a: AList3, b: BList3) { + a = b; + b = a; // Error +} + +interface AList4 { + forEach(cb: (item: A) => A): void; +} + +interface BList4 { + forEach(cb: (item: B) => B): void; +} + +function f14(a: AList4, b: BList4) { + a = b; + b = a; // Error +} diff --git a/tslint.json b/tslint.json index 92bfed07c95..9552d193a70 100644 --- a/tslint.json +++ b/tslint.json @@ -60,6 +60,8 @@ "object-literal-surrounding-space": true, "no-type-assertion-whitespace": true, "no-in-operator": true, + "no-switch-case-fall-through": true, + "triple-equals": true, "jsdoc-format": true } }