diff --git a/.mailmap b/.mailmap index 73ebed0cc7c..97941bcdf5a 100644 --- a/.mailmap +++ b/.mailmap @@ -248,4 +248,23 @@ rdosanjh # Raj Dosanjh gdh1995 # Dahan Gong cedvdb # @cedvdb kpreisser # K. Preißer -e-cloud # @e-cloud \ No newline at end of file +e-cloud # @e-cloud +Andrew Casey Andrew Casey +Andrew Stegmaier +Benny Neugebauer +Blaine Bublitz +Charles Pierce +Daniel Król +Diogo Franco (Kovensky) +Donald Pipowitch +Halasi Tamás +Ika +Joe Chung +Kate Miháliková +Mohsen Azimi +Noel Varanda +Reiner Dolp +t_ # @t_ +TravCav # @TravCav +Vladimir Kurchatkin +William Orr \ No newline at end of file diff --git a/AUTHORS.md b/AUTHORS.md index 4772d5371fa..824c696ce4f 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -15,7 +15,9 @@ TypeScript is authored by: * Anders Hejlsberg * Andreas Martin * Andrej Baran +* Andrew Casey * Andrew Ochsner +* Andrew Stegmaier * Andrew Z Allen * András Parditka * Andy Hanson @@ -31,7 +33,9 @@ TypeScript is authored by: * Ben Duffield * Ben Mosher * Benjamin Bock +* Benny Neugebauer * Bill Ticehurst +* Blaine Bublitz * Blake Embrey * @bootstraponline * Bowden Kelly @@ -39,6 +43,7 @@ TypeScript is authored by: * Bryan Forbes * Caitlin Potter * @cedvdb +* Charles Pierce * Charly POLY * Chris Bubernak * Christophe Vidal @@ -52,6 +57,7 @@ TypeScript is authored by: * Dan Corder * Dan Quirk * Daniel Hollocher +* Daniel Król * Daniel Lehenbauer * Daniel Rosenwasser * David Kmenta @@ -60,9 +66,11 @@ TypeScript is authored by: * David Souther * Denis Nedelyaev * Dick van den Brink +* Diogo Franco (Kovensky) * Dirk Bäumer * Dirk Holtwick * Dom Chen +* Donald Pipowitch * Doug Ilijev * @e-cloud * Elisée Maurer @@ -89,12 +97,14 @@ TypeScript is authored by: * Guilherme Oenning * Guillaume Salles * Guy Bedford +* Halasi Tamás * Harald Niesche * Hendrik Liebau * Herrington Darkholme * Homa Wong * Iain Monro * Igor Novozhilov +* Ika * Ingvar Stepanyan * Isiah Meadows * Ivo Gabe de Wolff @@ -111,6 +121,7 @@ TypeScript is authored by: * Jeffrey Morlan * Jesse Schalken * Jiri Tobisek +* Joe Chung * Joel Day * Joey Wilson * Johannes Rieken @@ -131,6 +142,7 @@ TypeScript is authored by: * K. Preißer * Kagami Sascha Rosylight * Kanchalai Tanglertsampan +* Kate Miháliková * Keith Mashinter * Ken Howard * Kenji Imamula @@ -159,6 +171,7 @@ TypeScript is authored by: * Mike Busyrev * Mine Starks * Mohamed Hegazy +* Mohsen Azimi * Myles Megyesi * Natalie Coley * Nathan Shively-Sanders @@ -166,6 +179,7 @@ TypeScript is authored by: * Nicolas Henry * Nima Zahedi * Noah Chen +* Noel Varanda * Noj Vek * Oleg Mihailik * Oleksandr Chekhovskyi @@ -186,6 +200,7 @@ TypeScript is authored by: * Punya Biswal * Rado Kirov * Raj Dosanjh +* Reiner Dolp * Richard Karmazín * Richard Knoll * Richard Sentino @@ -213,6 +228,7 @@ TypeScript is authored by: * Sudheesh Singanamalla * Sébastien Arod * @T18970237136 +* @t_ * Tarik Ozket * Tetsuharu Ohzeki * Thomas Loubiou @@ -225,13 +241,16 @@ TypeScript is authored by: * togru * Tomas Grubliauskas * Torben Fitschen +* @TravCav * TruongSinh Tran-Nguyen * Vadi Taslim * Vidar Tonaas Fauske * Viktor Zozulyak * Vilic Vane +* Vladimir Kurchatkin * Vladimir Matveev * Wesley Wigham +* William Orr * York Yao * @yortus * Yuichi Nukiyama diff --git a/Gulpfile.ts b/Gulpfile.ts index d856254296e..aef7cc4c6dd 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -39,25 +39,25 @@ Error.stackTraceLimit = 1000; const cmdLineOptions = minimist(process.argv.slice(2), { boolean: ["debug", "inspect", "light", "colors", "lint", "soft"], - string: ["browser", "tests", "host", "reporter", "stackTraceLimit"], + string: ["browser", "tests", "host", "reporter", "stackTraceLimit", "timeout"], alias: { b: "browser", - d: "debug", - t: "tests", - test: "tests", + d: "debug", "debug-brk": "debug", + i: "inspect", "inspect-brk": "inspect", + t: "tests", test: "tests", r: "reporter", - color: "colors", - f: "files", - file: "files", + c: "colors", color: "colors", + f: "files", file: "files", w: "workers", }, default: { soft: false, colors: process.env.colors || process.env.color || true, - debug: process.env.debug || process.env.d, - inspect: process.env.inspect, + debug: process.env.debug || process.env["debug-brk"] || process.env.d, + inspect: process.env.inspect || process.env["inspect-brk"] || process.env.i, host: process.env.TYPESCRIPT_HOST || process.env.host || "node", browser: process.env.browser || process.env.b || "IE", + timeout: process.env.timeout || 40000, tests: process.env.test || process.env.tests || process.env.t, light: process.env.light || false, reporter: process.env.reporter || process.env.r, @@ -594,11 +594,11 @@ function restoreSavedNodeEnv() { process.env.NODE_ENV = savedNodeEnv; } -let testTimeout = 40000; function runConsoleTests(defaultReporter: string, runInParallel: boolean, done: (e?: any) => void) { const lintFlag = cmdLineOptions["lint"]; cleanTestDirs((err) => { if (err) { console.error(err); failWithStatus(err, 1); } + let testTimeout = cmdLineOptions["timeout"]; const debug = cmdLineOptions["debug"]; const inspect = cmdLineOptions["inspect"]; const tests = cmdLineOptions["tests"]; @@ -637,12 +637,6 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done: // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer if (!runInParallel) { const args = []; - if (inspect) { - args.push("--inspect"); - } - if (inspect || debug) { - args.push("--debug-brk"); - } args.push("-R", reporter); if (tests) { args.push("-g", `"${tests}"`); @@ -653,7 +647,15 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done: else { args.push("--no-colors"); } - args.push("-t", testTimeout); + if (inspect) { + args.unshift("--inspect-brk"); + } + else if (debug) { + args.unshift("--debug-brk"); + } + else { + args.push("-t", testTimeout); + } args.push(run); setNodeEnvToDevelopment(); exec(mocha, args, lintThenFinish, function(e, status) { @@ -838,6 +840,7 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like ' }); gulp.task("generate-code-coverage", "Generates code coverage data via istanbul", ["tests"], (done) => { + const testTimeout = cmdLineOptions["timeout"]; exec("istanbul", ["cover", "node_modules/mocha/bin/_mocha", "--", "-R", "min", "-t", testTimeout.toString(), run], done, done); }); diff --git a/Jakefile.js b/Jakefile.js index 900859f033a..3de055b498e 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -25,6 +25,8 @@ var LKGDirectory = "lib/"; var copyright = "CopyrightNotice.txt"; var thirdParty = "ThirdPartyNoticeText.txt"; +var defaultTestTimeout = 40000; + // add node_modules to path so we don't need global modules, prefer the modules by adding them first var nodeModulesPathPrefix = path.resolve("./node_modules/.bin/") + path.delimiter; if (process.env.path !== undefined) { @@ -74,6 +76,10 @@ function measure(marker) { console.log("travis_time:end:" + marker.id + ":start=" + toNs(marker.stamp) + ",finish=" + toNs(total) + ",duration=" + toNs(diff) + "\r"); } +function removeConstModifierFromEnumDeclarations(text) { + return text.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, '$1$2enum $3 {$4'); +} + var compilerSources = filesFromConfig("./src/compiler/tsconfig.json"); var servicesSources = filesFromConfig("./src/services/tsconfig.json"); var cancellationTokenSources = filesFromConfig(path.join(serverDirectory, "cancellationToken/tsconfig.json")); @@ -551,7 +557,7 @@ compileFile(servicesFile, servicesSources, [builtLocalDirectory, copyright].conc // Stanalone/web definition file using global 'ts' namespace jake.cpR(standaloneDefinitionsFile, nodeDefinitionsFile, { silent: true }); var definitionFileContents = fs.readFileSync(nodeDefinitionsFile).toString(); - definitionFileContents = definitionFileContents.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, '$1$2enum $3 {$4'); + definitionFileContents = removeConstModifierFromEnumDeclarations(definitionFileContents) fs.writeFileSync(standaloneDefinitionsFile, definitionFileContents); // Official node package definition file, pointed to by 'typings' in package.json @@ -611,6 +617,7 @@ compileFile( fs.readFileSync(tsserverLibraryDefinitionFile).toString() + "\r\nexport = ts;" + "\r\nexport as namespace ts;"; + tsserverLibraryDefinitionFileContents = removeConstModifierFromEnumDeclarations(tsserverLibraryDefinitionFileContents); fs.writeFileSync(tsserverLibraryDefinitionFile, tsserverLibraryDefinitionFileContents); }); @@ -800,8 +807,8 @@ function runConsoleTests(defaultReporter, runInParallel) { cleanTestDirs(); } - var debug = process.env.debug || process.env.d; - var inspect = process.env.inspect; + var debug = process.env.debug || process.env["debug-brk"] || process.env.d; + var inspect = process.env.inspect || process.env["inspect-brk"] || process.env.i; var testTimeout = process.env.timeout || defaultTestTimeout; var tests = process.env.test || process.env.tests || process.env.t; var light = process.env.light || false; @@ -842,12 +849,6 @@ function runConsoleTests(defaultReporter, runInParallel) { if (!runInParallel) { var startTime = mark(); var args = []; - if (inspect) { - args.push("--inspect"); - } - if (inspect || debug) { - args.push("--debug-brk"); - } args.push("-R", reporter); if (tests) { args.push("-g", `"${tests}"`); @@ -861,7 +862,15 @@ function runConsoleTests(defaultReporter, runInParallel) { if (bail) { args.push("--bail"); } - args.push("-t", testTimeout); + if (inspect) { + args.unshift("--inspect-brk"); + } + else if (debug) { + args.unshift("--debug-brk"); + } + else { + args.push("-t", testTimeout); + } args.push(run); var cmd = "mocha " + args.join(" "); @@ -926,7 +935,6 @@ function runConsoleTests(defaultReporter, runInParallel) { } } -var defaultTestTimeout = 22000; desc("Runs all the tests in parallel using the built run.js file. Optional arguments are: t[ests]=category1|category2|... d[ebug]=true."); task("runtests-parallel", ["build-rules", "tests", builtLocalDirectory], function () { runConsoleTests('min', /*runInParallel*/ true); @@ -939,6 +947,7 @@ task("runtests", ["build-rules", "tests", builtLocalDirectory], function() { desc("Generates code coverage data via instanbul"); task("generate-code-coverage", ["tests", builtLocalDirectory], function () { + var testTimeout = process.env.timeout || defaultTestTimeout; var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run; console.log(cmd); exec(cmd); diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 22209e2e41e..ba5022a7b3c 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -612,7 +612,7 @@ namespace ts { break; case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: - bindForInOrForOfStatement(node); + bindForInOrForOfStatement(node); break; case SyntaxKind.IfStatement: bindIfStatement(node); @@ -950,7 +950,7 @@ namespace ts { currentFlow = finishFlowLabel(postLoopLabel); } - function bindForInOrForOfStatement(node: ForInStatement | ForOfStatement): void { + function bindForInOrForOfStatement(node: ForInOrOfStatement): void { const preLoopLabel = createLoopLabel(); const postLoopLabel = createBranchLabel(); addAntecedent(preLoopLabel, currentFlow); @@ -1328,7 +1328,7 @@ namespace ts { function bindVariableDeclarationFlow(node: VariableDeclaration) { bindEachChild(node); - if (node.initializer || node.parent.parent.kind === SyntaxKind.ForInStatement || node.parent.parent.kind === SyntaxKind.ForOfStatement) { + if (node.initializer || isForInOrOfStatement(node.parent.parent)) { bindInitializedVariableFlow(node); } } @@ -1521,7 +1521,7 @@ namespace ts { // All the children of these container types are never visible through another // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, // they're only accessed 'lexically' (i.e. from code that exists underneath - // their container in the tree. To accomplish this, we simply add their declared + // their container in the tree). To accomplish this, we simply add their declared // symbol to the 'locals' of the container. These symbols can then be found as // the type checker walks up the containers, checking them for matching names. return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes); @@ -2053,7 +2053,10 @@ namespace ts { case SyntaxKind.TypePredicate: return checkTypePredicate(node as TypePredicateNode); case SyntaxKind.TypeParameter: - return declareSymbolAndAddToSymbolTable(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); + if (node.parent.kind !== ts.SyntaxKind.JSDocTemplateTag || isInJavaScriptFile(node)) { + return declareSymbolAndAddToSymbolTable(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); + } + return; case SyntaxKind.Parameter: return bindParameter(node); case SyntaxKind.VariableDeclaration: @@ -2135,8 +2138,10 @@ namespace ts { case SyntaxKind.EnumDeclaration: return bindEnumDeclaration(node); case SyntaxKind.ModuleDeclaration: - return bindModuleDeclaration(node); - + if (node.parent.kind !== ts.SyntaxKind.JSDocTypedefTag || isInJavaScriptFile(node)) { + return bindModuleDeclaration(node); + } + return undefined; // Jsx-attributes case SyntaxKind.JsxAttributes: return bindJsxAttributes(node); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cb855969ea8..49248144524 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -804,16 +804,8 @@ namespace ts { break; } - switch (declaration.parent.parent.kind) { - case SyntaxKind.ForInStatement: - case SyntaxKind.ForOfStatement: - // ForIn/ForOf case - use site should not be used in expression part - if (isSameScopeDescendentOf(usage, (declaration.parent.parent).expression, container)) { - return true; - } - } - - return false; + // ForIn/ForOf case - use site should not be used in expression part + return isForInOrOfStatement(declaration.parent.parent) && isSameScopeDescendentOf(usage, declaration.parent.parent.expression, container); } function isUsedInFunctionOrInstanceProperty(usage: Node, declaration: Node, container?: Node): boolean { @@ -4200,16 +4192,6 @@ namespace ts { // Return the inferred type for a variable, parameter, or property declaration function getTypeForVariableLikeDeclaration(declaration: VariableLikeDeclaration, includeOptionality: boolean): Type { - if (declaration.flags & NodeFlags.JavaScriptFile) { - // If this is a variable in a JavaScript file, then use the JSDoc type (if it has - // one as its type), otherwise fallback to the below standard TS codepaths to - // try to figure it out. - const type = getTypeForDeclarationFromJSDocComment(declaration); - if (type && type !== unknownType) { - return type; - } - } - // A variable declared in a for..in statement is of type string, or of type keyof T when the // right hand expression is of a type parameter type. if (declaration.parent.parent.kind === SyntaxKind.ForInStatement) { @@ -4231,8 +4213,9 @@ namespace ts { } // Use type from type annotation if one is present - if (declaration.type) { - const declaredType = getTypeFromTypeNode(declaration.type); + const typeNode = getEffectiveTypeAnnotationNode(declaration); + if (typeNode) { + const declaredType = getTypeFromTypeNode(typeNode); return addOptionality(declaredType, /*optional*/ declaration.questionToken && includeOptionality); } @@ -4523,10 +4506,11 @@ namespace ts { function getAnnotatedAccessorType(accessor: AccessorDeclaration): Type { if (accessor) { if (accessor.kind === SyntaxKind.GetAccessor) { - return accessor.type && getTypeFromTypeNode(accessor.type); + const getterTypeAnnotation = getEffectiveReturnTypeNode(accessor); + return getterTypeAnnotation && getTypeFromTypeNode(getterTypeAnnotation); } else { - const setterTypeAnnotation = getSetAccessorTypeAnnotationNode(accessor); + const setterTypeAnnotation = getEffectiveSetAccessorTypeAnnotationNode(accessor); return setterTypeAnnotation && getTypeFromTypeNode(setterTypeAnnotation); } } @@ -4679,7 +4663,7 @@ namespace ts { function reportCircularityError(symbol: Symbol) { // Check if variable has type annotation that circularly references the variable itself - if ((symbol.valueDeclaration).type) { + if (getEffectiveTypeAnnotationNode(symbol.valueDeclaration)) { error(symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol)); return unknownType; @@ -5265,14 +5249,18 @@ namespace ts { // A variable-like declaration is considered independent (free of this references) if it has a type annotation // that specifies an independent type, or if it has no type annotation and no initializer (and thus of type any). function isIndependentVariableLikeDeclaration(node: VariableLikeDeclaration): boolean { - return node.type && isIndependentType(node.type) || !node.type && !node.initializer; + const typeNode = getEffectiveTypeAnnotationNode(node); + return typeNode ? isIndependentType(typeNode) : !node.initializer; } // A function-like declaration is considered independent (free of this references) if it has a return type // annotation that is considered independent and if each parameter is considered independent. function isIndependentFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean { - if (node.kind !== SyntaxKind.Constructor && (!node.type || !isIndependentType(node.type))) { - return false; + if (node.kind !== SyntaxKind.Constructor) { + const typeNode = getEffectiveReturnTypeNode(node); + if (!typeNode || !isIndependentType(typeNode)) { + return false; + } } for (const parameter of node.parameters) { if (!isIndependentVariableLikeDeclaration(parameter)) { @@ -5985,7 +5973,7 @@ namespace ts { typeParameter.default = targetDefault ? instantiateType(targetDefault, typeParameter.mapper) : noConstraintType; } else { - const defaultDeclaration = typeParameter.symbol && forEach(typeParameter.symbol.declarations, decl => isTypeParameter(decl) && decl.default); + const defaultDeclaration = typeParameter.symbol && forEach(typeParameter.symbol.declarations, decl => isTypeParameterDeclaration(decl) && decl.default); typeParameter.default = defaultDeclaration ? getTypeFromTypeNode(defaultDeclaration) : noConstraintType; } } @@ -6182,24 +6170,16 @@ namespace ts { return undefined; } - function getTypeParametersFromJSDocTemplate(declaration: SignatureDeclaration): TypeParameter[] { - if (declaration.flags & NodeFlags.JavaScriptFile) { - const templateTag = getJSDocTemplateTag(declaration); - if (templateTag) { - return getTypeParametersFromDeclaration(templateTag.typeParameters); - } - } - - return undefined; - } - // Return list of type parameters with duplicates removed (duplicate identifier errors are generated in the actual // type checking functions). - function getTypeParametersFromDeclaration(typeParameterDeclarations: TypeParameterDeclaration[]): TypeParameter[] { - const result: TypeParameter[] = []; - forEach(typeParameterDeclarations, node => { + function getTypeParametersFromDeclaration(declaration: DeclarationWithTypeParameters): TypeParameter[] { + let result: TypeParameter[]; + forEach(getEffectiveTypeParameterDeclarations(declaration), node => { const tp = getDeclaredTypeOfTypeParameter(node.symbol); if (!contains(result, tp)) { + if (!result) { + result = []; + } result.push(tp); } }); @@ -6395,9 +6375,7 @@ namespace ts { const classType = declaration.kind === SyntaxKind.Constructor ? getDeclaredTypeOfClassOrInterface(getMergedSymbol((declaration.parent).symbol)) : undefined; - const typeParameters = classType ? classType.localTypeParameters : - declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : - getTypeParametersFromJSDocTemplate(declaration); + const typeParameters = classType ? classType.localTypeParameters : getTypeParametersFromDeclaration(declaration); const returnType = getSignatureReturnTypeFromDeclaration(declaration, isJSConstructSignature, classType); const typePredicate = declaration.type && declaration.type.kind === SyntaxKind.TypePredicate ? createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) : @@ -6424,15 +6402,10 @@ namespace ts { else if (classType) { return classType; } - else if (declaration.type) { - return getTypeFromTypeNode(declaration.type); - } - if (declaration.flags & NodeFlags.JavaScriptFile) { - const type = getReturnTypeFromJSDocComment(declaration); - if (type && type !== unknownType) { - return type; - } + const typeNode = getEffectiveReturnTypeNode(declaration); + if (typeNode) { + return getTypeFromTypeNode(typeNode); } // TypeScript 1.0 spec (April 2014): @@ -6841,21 +6814,46 @@ namespace ts { return undefined; } - function resolveTypeReferenceName(typeReferenceName: EntityNameExpression | EntityName) { + function resolveTypeReferenceName(typeReferenceName: EntityNameExpression | EntityName, meaning: SymbolFlags) { if (!typeReferenceName) { return unknownSymbol; } - return resolveEntityName(typeReferenceName, SymbolFlags.Type) || unknownSymbol; + return resolveEntityName(typeReferenceName, meaning) || unknownSymbol; } function getTypeReferenceType(node: TypeReferenceType, symbol: Symbol) { const typeArguments = typeArgumentsFromTypeReferenceNode(node); // Do unconditionally so we mark type arguments as referenced. - if (symbol === unknownSymbol) { return unknownType; } + const type = getTypeReferenceTypeWorker(node, symbol, typeArguments); + if (type) { + return type; + } + + if (symbol.flags & SymbolFlags.Value && node.kind === SyntaxKind.JSDocTypeReference) { + // A JSDocTypeReference may have resolved to a value (as opposed to a type). If + // the symbol is a constructor function, return the inferred class type; otherwise, + // the type of this reference is just the type of the value we resolved to. + const valueType = getTypeOfSymbol(symbol); + if (valueType.symbol && !isInferredClassType(valueType)) { + const referenceType = getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments); + if (referenceType) { + return referenceType; + } + } + + // Resolve the type reference as a Type for the purpose of reporting errors. + resolveTypeReferenceName(getTypeReferenceName(node), SymbolFlags.Type); + return valueType; + } + + return getTypeFromNonGenericTypeReference(node, symbol); + } + + function getTypeReferenceTypeWorker(node: TypeReferenceType, symbol: Symbol, typeArguments: Type[]): Type | undefined { if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { return getTypeFromClassOrInterfaceReference(node, symbol, typeArguments); } @@ -6864,14 +6862,9 @@ namespace ts { return getTypeFromTypeAliasReference(node, symbol, typeArguments); } - if (symbol.flags & SymbolFlags.Value && node.kind === SyntaxKind.JSDocTypeReference) { - // A JSDocTypeReference may have resolved to a value (as opposed to a type). In - // that case, the type of this reference is just the type of the value we resolved - // to. - return getTypeOfSymbol(symbol); + if (symbol.flags & SymbolFlags.Function && node.kind === SyntaxKind.JSDocTypeReference && (symbol.members || getJSDocClassTag(symbol.valueDeclaration))) { + return getInferredClassType(symbol); } - - return getTypeFromNonGenericTypeReference(node, symbol); } function getPrimitiveTypeFromJSDocTypeReference(node: JSDocTypeReference): Type { @@ -6914,22 +6907,13 @@ namespace ts { if (!links.resolvedType) { let symbol: Symbol; let type: Type; + let meaning = SymbolFlags.Type; if (node.kind === SyntaxKind.JSDocTypeReference) { - type = getPrimitiveTypeFromJSDocTypeReference(node); - if (!type) { - const typeReferenceName = getTypeReferenceName(node); - symbol = resolveTypeReferenceName(typeReferenceName); - type = getTypeReferenceType(node, symbol); - } + type = getPrimitiveTypeFromJSDocTypeReference(node); + meaning |= SymbolFlags.Value; } - else { - // We only support expressions that are simple qualified names. For other expressions this produces undefined. - const typeNameOrExpression: EntityNameOrEntityNameExpression = node.kind === SyntaxKind.TypeReference - ? (node).typeName - : isEntityNameExpression((node).expression) - ? (node).expression - : undefined; - symbol = typeNameOrExpression && resolveEntityName(typeNameOrExpression, SymbolFlags.Type) || unknownSymbol; + if (!type) { + symbol = resolveTypeReferenceName(getTypeReferenceName(node), meaning); type = getTypeReferenceType(node, symbol); } // Cache both the resolved symbol and the resolved type. The resolved symbol is needed in when we check the @@ -7166,6 +7150,7 @@ namespace ts { containsAny?: boolean; containsUndefined?: boolean; containsNull?: boolean; + containsNever?: boolean; containsNonWideningType?: boolean; containsString?: boolean; containsNumber?: boolean; @@ -7367,10 +7352,13 @@ namespace ts { else if (type.flags & TypeFlags.Any) { typeSet.containsAny = true; } + else if (type.flags & TypeFlags.Never) { + typeSet.containsNever = true; + } else if (getObjectFlags(type) & ObjectFlags.Anonymous && isEmptyObjectType(type)) { typeSet.containsEmptyObject = true; } - else if (!(type.flags & TypeFlags.Never) && (strictNullChecks || !(type.flags & TypeFlags.Nullable)) && !contains(typeSet, type)) { + else if ((strictNullChecks || !(type.flags & TypeFlags.Nullable)) && !contains(typeSet, type)) { if (type.flags & TypeFlags.Object) { typeSet.containsObjectType = true; } @@ -7408,6 +7396,9 @@ namespace ts { } const typeSet = [] as TypeSet; addTypesToIntersection(typeSet, types); + if (typeSet.containsNever) { + return neverType; + } if (typeSet.containsAny) { return anyType; } @@ -8058,7 +8049,7 @@ namespace ts { const result = createSignature(signature.declaration, freshTypeParameters, signature.thisParameter && instantiateSymbol(signature.thisParameter, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), - instantiateType(signature.resolvedReturnType, mapper), + /*resolvedReturnType*/ undefined, freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasLiteralTypes); result.target = signature; @@ -8165,9 +8156,9 @@ namespace ts { case SyntaxKind.ClassExpression: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.TypeAliasDeclaration: - const declaration = node as DeclarationWithTypeParameters; - if (declaration.typeParameters) { - for (const d of declaration.typeParameters) { + const typeParameters = getEffectiveTypeParameterDeclarations(node as DeclarationWithTypeParameters); + if (typeParameters) { + for (const d of typeParameters) { if (contains(mappedTypes, getDeclaredTypeOfTypeParameter(getSymbolOfNode(d)))) { return true; } @@ -8322,7 +8313,7 @@ namespace ts { return false; } // Functions with any parameters that lack type annotations are context sensitive. - if (forEach(node.parameters, p => !p.type)) { + if (forEach(node.parameters, p => !getEffectiveTypeAnnotationNode(p))) { return true; } // For arrow functions we now know we're not context sensitive. @@ -8449,10 +8440,9 @@ namespace ts { return Ternary.False; } - // Spec 1.0 Section 3.8.3 & 3.8.4: - // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N - source = getErasedSignature(source); - target = getErasedSignature(target); + if (source.typeParameters) { + source = instantiateSignatureInContextOf(source, target); + } let result = Ternary.True; @@ -8966,7 +8956,9 @@ namespace ts { reportError(Diagnostics.Property_0_does_not_exist_on_type_1, symbolToString(prop), typeToString(target)); } else { - errorNode = prop.valueDeclaration; + if (prop.valueDeclaration) { + errorNode = prop.valueDeclaration; + } reportError(Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(prop), typeToString(target)); } @@ -9488,23 +9480,33 @@ namespace ts { const saveErrorInfo = errorInfo; if (getObjectFlags(source) & ObjectFlags.Instantiated && getObjectFlags(target) & ObjectFlags.Instantiated && source.symbol === target.symbol) { - // We instantiations of the same anonymous type (which typically will be the type of a method). - // Simply do a pairwise comparison of the signatures in the two signature lists instead of the - // much more expensive N * M comparison matrix we explore below. + // We have instantiations of the same anonymous type (which typically will be the type of a + // method). Simply do a pairwise comparison of the signatures in the two signature lists instead + // of the much more expensive N * M comparison matrix we explore below. We erase type parameters + // as they are known to always be the same. for (let i = 0; i < targetSignatures.length; i++) { - const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], reportErrors); + const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], /*erase*/ true, reportErrors); if (!related) { return Ternary.False; } result &= related; } } + else if (sourceSignatures.length === 1 && targetSignatures.length === 1) { + // For simple functions (functions with a single signature) we only erase type parameters for + // the comparable relation. Otherwise, if the source signature is generic, we instantiate it + // in the context of the target signature before checking the relationship. Ideally we'd do + // this regardless of the number of signatures, but the potential costs are prohibitive due + // to the quadratic nature of the logic below. + const eraseGenerics = relation === comparableRelation || compilerOptions.noStrictGenericChecks; + result = signatureRelatedTo(sourceSignatures[0], targetSignatures[0], eraseGenerics, reportErrors); + } else { outer: for (const t of targetSignatures) { // Only elaborate errors from the first failure let shouldElaborateErrors = reportErrors; for (const s of sourceSignatures) { - const related = signatureRelatedTo(s, t, shouldElaborateErrors); + const related = signatureRelatedTo(s, t, /*erase*/ true, shouldElaborateErrors); if (related) { result &= related; errorInfo = saveErrorInfo; @@ -9527,8 +9529,9 @@ namespace ts { /** * See signatureAssignableTo, compareSignaturesIdentical */ - function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): Ternary { - return compareSignaturesRelated(source, target, /*checkAsCallback*/ false, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo); + function signatureRelatedTo(source: Signature, target: Signature, erase: boolean, reportErrors: boolean): Ternary { + return compareSignaturesRelated(erase ? getErasedSignature(source) : source, erase ? getErasedSignature(target) : target, + /*checkAsCallback*/ false, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo); } function signaturesIdenticalTo(source: Type, target: Type, kind: SignatureKind): Ternary { @@ -12741,8 +12744,15 @@ namespace ts { function getContextualTypeForInitializerExpression(node: Expression): Type { const declaration = node.parent; if (node === declaration.initializer) { - if (declaration.type) { - return getTypeFromTypeNode(declaration.type); + const typeNode = getEffectiveTypeAnnotationNode(declaration); + if (typeNode) { + return getTypeFromTypeNode(typeNode); + } + if (isInJavaScriptFile(declaration)) { + const jsDocType = getTypeForDeclarationFromJSDocComment(declaration); + if (jsDocType) { + return jsDocType; + } } if (declaration.kind === SyntaxKind.Parameter) { const type = getContextuallyTypedParameterType(declaration); @@ -12756,12 +12766,13 @@ namespace ts { if (isBindingPattern(declaration.parent)) { const parentDeclaration = declaration.parent.parent; const name = declaration.propertyName || declaration.name; - if (parentDeclaration.kind !== SyntaxKind.BindingElement && - parentDeclaration.type && - !isBindingPattern(name)) { - const text = getTextOfPropertyName(name); - if (text) { - return getTypeOfPropertyOfType(getTypeFromTypeNode(parentDeclaration.type), text); + if (parentDeclaration.kind !== SyntaxKind.BindingElement) { + const parentTypeNode = getEffectiveTypeAnnotationNode(parentDeclaration); + if (parentTypeNode && !isBindingPattern(name)) { + const text = getTextOfPropertyName(name); + if (text) { + return getTypeOfPropertyOfType(getTypeFromTypeNode(parentTypeNode), text); + } } } } @@ -12815,9 +12826,9 @@ namespace ts { function getContextualReturnType(functionDecl: FunctionLikeDeclaration): Type { // If the containing function has a return type annotation, is a constructor, or is a get accessor whose // corresponding set accessor has a type annotation, return statements in the function are contextually typed - if (functionDecl.type || - functionDecl.kind === SyntaxKind.Constructor || - functionDecl.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(getDeclarationOfKind(functionDecl.symbol, SyntaxKind.SetAccessor))) { + if (functionDecl.kind === SyntaxKind.Constructor || + getEffectiveReturnTypeNode(functionDecl) || + isGetAccessorWithAnnotatedSetAccessor(functionDecl)) { return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); } @@ -14214,9 +14225,13 @@ namespace ts { /** * Check if a property with the given name is known anywhere in the given type. In an object type, a property - * is considered known if the object type is empty and the check is for assignability, if the object type has - * index signatures, or if the property is actually declared in the object type. In a union or intersection - * type, a property is considered known if it is known in any constituent type. + * is considered known if + * 1. the object type is empty and the check is for assignability, or + * 2. if the object type has index signatures, or + * 3. if the property is actually declared in the object type + * (this means that 'toString', for example, is not usually a known property). + * 4. In a union or intersection type, + * a property is considered known if it is known in any constituent type. * @param targetType a type to search a given name in * @param name a property name to search * @param isComparingJsxAttributes a boolean flag indicating whether we are searching in JsxAttributesType @@ -14226,7 +14241,7 @@ namespace ts { const resolved = resolveStructuredTypeMembers(targetType); if (resolved.stringIndexInfo || resolved.numberIndexInfo && isNumericLiteralName(name) || - getPropertyOfType(targetType, name) || + getPropertyOfObjectType(targetType, name) || isComparingJsxAttributes && !isUnhyphenatedJsxName(name)) { // For JSXAttributes, if the attribute has a hyphenated name, consider that the attribute to be known. return true; @@ -14964,12 +14979,15 @@ namespace ts { } // Instantiate a generic signature in the context of a non-generic signature (section 3.8.5 in TypeScript spec) - function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper: TypeMapper): Signature { + function instantiateSignatureInContextOf(signature: Signature, contextualSignature: Signature, contextualMapper?: TypeMapper): Signature { const context = createInferenceContext(signature, InferenceFlags.InferUnionTypes); forEachMatchingParameterType(contextualSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type - inferTypes(context.inferences, instantiateType(source, contextualMapper), target); + inferTypes(context.inferences, instantiateType(source, contextualMapper || identityMapper), target); }); + if (!contextualMapper) { + inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), InferencePriority.ReturnType); + } return getSignatureInstantiation(signature, getInferredTypes(context)); } @@ -15009,10 +15027,10 @@ namespace ts { // outer call expression. Effectively we just want a snapshot of whatever has been // inferred for any outer call expression so far. const instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node))); - // If the contextual type is a generic pure function type, we instantiate the type with - // its own type parameters and type arguments. This ensures that the type parameters are - // not erased to type any during type inference such that they can be inferred as actual - // types from the contextual type. For example: + // If the contextual type is a generic function type with a single call signature, we + // instantiate the type with its own type parameters and type arguments. This ensures that + // the type parameters are not erased to type any during type inference such that they can + // be inferred as actual types from the contextual type. For example: // declare function arrayMap(f: (x: T) => U): (a: T[]) => U[]; // const boxElements: (a: A[]) => { value: A }[] = arrayMap(value => ({ value })); // Above, the type of the 'value' parameter is inferred to be 'A'. @@ -16169,6 +16187,12 @@ namespace ts { return links.inferredClassType; } + function isInferredClassType(type: Type) { + return type.symbol + && getObjectFlags(type) & ObjectFlags.Anonymous + && getSymbolLinks(type.symbol).inferredClassType === type; + } + /** * Syntactically and semantically checks a call or new expression. * @param node The call/new expression to be checked. @@ -16340,37 +16364,43 @@ namespace ts { return signature.parameters.length > 0 ? getTypeAtPosition(signature, 0) : neverType; } - function assignContextualParameterTypes(signature: Signature, context: Signature, mapper: TypeMapper, checkMode: CheckMode) { + function inferFromAnnotatedParameters(signature: Signature, context: Signature, mapper: TypeMapper) { const len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0); - if (checkMode === CheckMode.Inferential) { - for (let i = 0; i < len; i++) { - const declaration = signature.parameters[i].valueDeclaration; - if (declaration.type) { - inferTypes((mapper).inferences, getTypeFromTypeNode(declaration.type), getTypeAtPosition(context, i)); + for (let i = 0; i < len; i++) { + const declaration = signature.parameters[i].valueDeclaration; + if (declaration.type) { + const typeNode = getEffectiveTypeAnnotationNode(declaration); + if (typeNode) { + inferTypes((mapper).inferences, getTypeFromTypeNode(typeNode), getTypeAtPosition(context, i)); } } } + } + + function assignContextualParameterTypes(signature: Signature, context: Signature) { + signature.typeParameters = context.typeParameters; if (context.thisParameter) { const parameter = signature.thisParameter; if (!parameter || parameter.valueDeclaration && !(parameter.valueDeclaration).type) { if (!parameter) { signature.thisParameter = createSymbolWithType(context.thisParameter, /*type*/ undefined); } - assignTypeToParameterAndFixTypeParameters(signature.thisParameter, getTypeOfSymbol(context.thisParameter), mapper, checkMode); + assignTypeToParameterAndFixTypeParameters(signature.thisParameter, getTypeOfSymbol(context.thisParameter)); } } + const len = signature.parameters.length - (signature.hasRestParameter ? 1 : 0); for (let i = 0; i < len; i++) { const parameter = signature.parameters[i]; - if (!(parameter.valueDeclaration).type) { + if (!getEffectiveTypeAnnotationNode(parameter.valueDeclaration)) { const contextualParameterType = getTypeAtPosition(context, i); - assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper, checkMode); + assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType); } } if (signature.hasRestParameter && isRestParameterIndex(context, signature.parameters.length - 1)) { const parameter = lastOrUndefined(signature.parameters); - if (!(parameter.valueDeclaration).type) { + if (!getEffectiveTypeAnnotationNode(parameter.valueDeclaration)) { const contextualParameterType = getTypeOfSymbol(lastOrUndefined(context.parameters)); - assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, mapper, checkMode); + assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType); } } } @@ -16390,10 +16420,10 @@ namespace ts { } } - function assignTypeToParameterAndFixTypeParameters(parameter: Symbol, contextualType: Type, mapper: TypeMapper, checkMode: CheckMode) { + function assignTypeToParameterAndFixTypeParameters(parameter: Symbol, contextualType: Type) { const links = getSymbolLinks(parameter); if (!links.type) { - links.type = instantiateType(contextualType, mapper); + links.type = contextualType; const name = getNameOfDeclaration(parameter.valueDeclaration); // if inference didn't come up with anything but {}, fall back to the binding pattern if present. if (links.type === emptyObjectType && @@ -16402,47 +16432,6 @@ namespace ts { } assignBindingElementTypes(parameter.valueDeclaration); } - else if (checkMode === CheckMode.Inferential) { - // Even if the parameter already has a type, it might be because it was given a type while - // processing the function as an argument to a prior signature during overload resolution. - // If this was the case, it may have caused some type parameters to be fixed. So here, - // we need to ensure that type parameters at the same positions get fixed again. This is - // done by calling instantiateType to attach the mapper to the contextualType, and then - // calling inferTypes to force a walk of contextualType so that all the correct fixing - // happens. The choice to pass in links.type may seem kind of arbitrary, but it serves - // to make sure that all the correct positions in contextualType are reached by the walk. - // Here is an example: - // - // interface Base { - // baseProp; - // } - // interface Derived extends Base { - // toBase(): Base; - // } - // - // var derived: Derived; - // - // declare function foo(x: T, func: (p: T) => T): T; - // declare function foo(x: T, func: (p: T) => T): T; - // - // var result = foo(derived, d => d.toBase()); - // - // We are typing d while checking the second overload. But we've already given d - // a type (Derived) from the first overload. However, we still want to fix the - // T in the second overload so that we do not infer Base as a candidate for T - // (inferring Base would make type argument inference inconsistent between the two - // overloads). - inferTypes((mapper).inferences, links.type, instantiateType(contextualType, mapper)); - } - } - - function getReturnTypeFromJSDocComment(func: SignatureDeclaration | FunctionDeclaration): Type { - const returnTag = getJSDocReturnTag(func); - if (returnTag && returnTag.typeExpression) { - return getTypeFromTypeNode(returnTag.typeExpression.type); - } - - return undefined; } function createPromiseType(promisedType: Type): Type { @@ -16670,16 +16659,16 @@ namespace ts { const hasExplicitReturn = func.flags & NodeFlags.HasExplicitReturn; if (returnType && returnType.flags & TypeFlags.Never) { - error(func.type, Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point); + error(getEffectiveReturnTypeNode(func), Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point); } else if (returnType && !hasExplicitReturn) { // minimal check: function has syntactic return type annotation and no explicit return statements in the body // this function does not conform to the specification. // NOTE: having returnType !== undefined is a precondition for entering this branch so func.type will always be present - error(func.type, Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value); + error(getEffectiveReturnTypeNode(func), Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value); } else if (returnType && strictNullChecks && !isTypeAssignableTo(undefinedType, returnType)) { - error(func.type, Diagnostics.Function_lacks_ending_return_statement_and_return_type_does_not_include_undefined); + error(getEffectiveReturnTypeNode(func), Diagnostics.Function_lacks_ending_return_statement_and_return_type_does_not_include_undefined); } else if (compilerOptions.noImplicitReturns) { if (!returnType) { @@ -16694,7 +16683,7 @@ namespace ts { return; } } - error(func.type || func, Diagnostics.Not_all_code_paths_return_a_value); + error(getEffectiveReturnTypeNode(func) || func, Diagnostics.Not_all_code_paths_return_a_value); } } @@ -16715,37 +16704,35 @@ namespace ts { const links = getNodeLinks(node); const type = getTypeOfSymbol(node.symbol); - const contextSensitive = isContextSensitive(node); - const mightFixTypeParameters = contextSensitive && checkMode === CheckMode.Inferential; // Check if function expression is contextually typed and assign parameter types if so. - // See the comment in assignTypeToParameterAndFixTypeParameters to understand why we need to - // check mightFixTypeParameters. - if (mightFixTypeParameters || !(links.flags & NodeCheckFlags.ContextChecked)) { + if (!(links.flags & NodeCheckFlags.ContextChecked)) { const contextualSignature = getContextualSignature(node); // If a type check is started at a function expression that is an argument of a function call, obtaining the // contextual type may recursively get back to here during overload resolution of the call. If so, we will have // already assigned contextual types. - const contextChecked = !!(links.flags & NodeCheckFlags.ContextChecked); - if (mightFixTypeParameters || !contextChecked) { + if (!(links.flags & NodeCheckFlags.ContextChecked)) { links.flags |= NodeCheckFlags.ContextChecked; if (contextualSignature) { const signature = getSignaturesOfType(type, SignatureKind.Call)[0]; - if (contextSensitive) { - assignContextualParameterTypes(signature, contextualSignature, getContextualMapper(node), checkMode); + if (isContextSensitive(node)) { + const contextualMapper = getContextualMapper(node); + if (checkMode === CheckMode.Inferential) { + inferFromAnnotatedParameters(signature, contextualSignature, contextualMapper); + } + const instantiatedContextualSignature = contextualMapper === identityMapper ? + contextualSignature : instantiateSignature(contextualSignature, contextualMapper); + assignContextualParameterTypes(signature, instantiatedContextualSignature); } - if (mightFixTypeParameters || !node.type && !signature.resolvedReturnType) { + if (!getEffectiveReturnTypeNode(node) && !signature.resolvedReturnType) { const returnType = getReturnTypeFromBody(node, checkMode); if (!signature.resolvedReturnType) { signature.resolvedReturnType = returnType; } } } - - if (!contextChecked) { - checkSignatureDeclaration(node); - checkNodeDeferred(node); - } + checkSignatureDeclaration(node); + checkNodeDeferred(node); } } @@ -16762,10 +16749,11 @@ namespace ts { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); const functionFlags = getFunctionFlags(node); - const returnOrPromisedType = node.type && + const returnTypeNode = getEffectiveReturnTypeNode(node); + const returnOrPromisedType = returnTypeNode && ((functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.Async ? checkAsyncFunctionReturnType(node) : // Async function - getTypeFromTypeNode(node.type)); // AsyncGenerator function, Generator function, or normal function + getTypeFromTypeNode(returnTypeNode)); // AsyncGenerator function, Generator function, or normal function if ((functionFlags & FunctionFlags.Generator) === 0) { // Async function or normal function // return is not necessary in the body of generators @@ -16773,7 +16761,7 @@ namespace ts { } if (node.body) { - if (!node.type) { + if (!returnTypeNode) { // There are some checks that are only performed in getReturnTypeFromBody, that may produce errors // we need. An example is the noImplicitAny errors resulting from widening the return expression // of a function. Because checking of function expression bodies is deferred, there was never an @@ -16865,7 +16853,7 @@ namespace ts { function checkReferenceExpression(expr: Expression, invalidReferenceMessage: DiagnosticMessage): boolean { // References are combinations of identifiers, parentheses, and property accesses. - const node = skipParentheses(expr); + const node = skipOuterExpressions(expr, OuterExpressionKinds.Assertions | OuterExpressionKinds.Parentheses); if (node.kind !== SyntaxKind.Identifier && node.kind !== SyntaxKind.PropertyAccessExpression && node.kind !== SyntaxKind.ElementAccessExpression) { error(expr, invalidReferenceMessage); return false; @@ -17559,8 +17547,9 @@ namespace ts { // There is no point in doing an assignability check if the function // has no explicit return type because the return type is directly computed // from the yield expressions. - if (func.type) { - const signatureElementType = getIteratedTypeOfGenerator(getTypeFromTypeNode(func.type), (functionFlags & FunctionFlags.Async) !== 0) || anyType; + const returnType = getEffectiveReturnTypeNode(func); + if (returnType) { + const signatureElementType = getIteratedTypeOfGenerator(getTypeFromTypeNode(returnType), (functionFlags & FunctionFlags.Async) !== 0) || anyType; if (nodeIsYieldStar) { checkTypeAssignableTo( functionFlags & FunctionFlags.Async @@ -17716,7 +17705,7 @@ namespace ts { if (signature && signature.typeParameters) { const contextualType = getApparentTypeOfContextualType(node); if (contextualType) { - const contextualSignature = getSingleCallSignature(contextualType); + const contextualSignature = getSingleCallSignature(getNonNullableType(contextualType)); if (contextualSignature && !contextualSignature.typeParameters) { return getOrCreateTypeFromSignature(instantiateSignatureInContextOf(signature, contextualSignature, getContextualMapper(node))); } @@ -18088,13 +18077,15 @@ namespace ts { forEach(node.parameters, checkParameter); + // TODO(rbuckton): Should we start checking JSDoc types? if (node.type) { checkSourceElement(node.type); } if (produceDiagnostics) { checkCollisionWithArgumentsInGeneratedCode(node); - if (noImplicitAny && !node.type) { + const returnTypeNode = getEffectiveReturnTypeNode(node); + if (noImplicitAny && !returnTypeNode) { switch (node.kind) { case SyntaxKind.ConstructSignature: error(node, Diagnostics.Construct_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type); @@ -18105,12 +18096,12 @@ namespace ts { } } - if (node.type) { + if (returnTypeNode) { const functionFlags = getFunctionFlags(node); if ((functionFlags & (FunctionFlags.Invalid | FunctionFlags.Generator)) === FunctionFlags.Generator) { - const returnType = getTypeFromTypeNode(node.type); + const returnType = getTypeFromTypeNode(returnTypeNode); if (returnType === voidType) { - error(node.type, Diagnostics.A_generator_cannot_have_a_void_type_annotation); + error(returnTypeNode, Diagnostics.A_generator_cannot_have_a_void_type_annotation); } else { const generatorElementType = getIteratedTypeOfGenerator(returnType, (functionFlags & FunctionFlags.Async) !== 0) || anyType; @@ -18124,7 +18115,7 @@ namespace ts { // interface BadGenerator extends Iterable, Iterator { } // function* g(): BadGenerator { } // Iterable and Iterator have different types! // - checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); + checkTypeAssignableTo(iterableIteratorInstantiation, returnType, returnTypeNode); } } else if ((functionFlags & FunctionFlags.AsyncGenerator) === FunctionFlags.Async) { @@ -19136,7 +19127,8 @@ namespace ts { // then(...): Promise; // } // - const returnType = getTypeFromTypeNode(node.type); + const returnTypeNode = getEffectiveReturnTypeNode(node); + const returnType = getTypeFromTypeNode(returnTypeNode); if (languageVersion >= ScriptTarget.ES2015) { if (returnType === unknownType) { @@ -19146,21 +19138,21 @@ namespace ts { if (globalPromiseType !== emptyGenericType && !isReferenceToType(returnType, globalPromiseType)) { // The promise type was not a valid type reference to the global promise type, so we // report an error and return the unknown type. - error(node.type, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type); + error(returnTypeNode, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type); return unknownType; } } else { // Always mark the type node as referenced if it points to a value - markTypeNodeAsReferenced(node.type); + markTypeNodeAsReferenced(returnTypeNode); if (returnType === unknownType) { return unknownType; } - const promiseConstructorName = getEntityNameFromTypeNode(node.type); + const promiseConstructorName = getEntityNameFromTypeNode(returnTypeNode); if (promiseConstructorName === undefined) { - error(node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, typeToString(returnType)); + error(returnTypeNode, Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, typeToString(returnType)); return unknownType; } @@ -19168,10 +19160,10 @@ namespace ts { const promiseConstructorType = promiseConstructorSymbol ? getTypeOfSymbol(promiseConstructorSymbol) : unknownType; if (promiseConstructorType === unknownType) { if (promiseConstructorName.kind === SyntaxKind.Identifier && promiseConstructorName.text === "Promise" && getTargetType(returnType) === getGlobalPromiseType(/*reportErrors*/ false)) { - error(node.type, Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); + error(returnTypeNode, Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); } else { - error(node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, entityNameToString(promiseConstructorName)); + error(returnTypeNode, Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, entityNameToString(promiseConstructorName)); } return unknownType; } @@ -19180,11 +19172,11 @@ namespace ts { if (globalPromiseConstructorLikeType === emptyObjectType) { // If we couldn't resolve the global PromiseConstructorLike type we cannot verify // compatibility with __awaiter. - error(node.type, Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, entityNameToString(promiseConstructorName)); + error(returnTypeNode, Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value, entityNameToString(promiseConstructorName)); return unknownType; } - if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node.type, + if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, returnTypeNode, Diagnostics.Type_0_is_not_a_valid_async_function_return_type_in_ES5_SlashES3_because_it_does_not_refer_to_a_Promise_compatible_constructor_value)) { return unknownType; } @@ -19329,7 +19321,8 @@ namespace ts { } function getParameterTypeNodeForDecoratorCheck(node: ParameterDeclaration): TypeNode { - return node.dotDotDotToken ? getRestParameterElementType(node.type) : node.type; + const typeNode = getEffectiveTypeAnnotationNode(node); + return isRestParameter(node) ? getRestParameterElementType(typeNode) : typeNode; } /** Check the decorators of a node */ @@ -19375,14 +19368,15 @@ namespace ts { markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(parameter)); } - markDecoratorMedataDataTypeNodeAsReferenced((node).type); + markDecoratorMedataDataTypeNodeAsReferenced(getEffectiveReturnTypeNode(node)); break; case SyntaxKind.PropertyDeclaration: - markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(node)); + markDecoratorMedataDataTypeNodeAsReferenced(getEffectiveTypeAnnotationNode(node)); break; + case SyntaxKind.Parameter: - markDecoratorMedataDataTypeNodeAsReferenced((node).type); + markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(node)); break; } } @@ -19392,8 +19386,8 @@ namespace ts { function checkFunctionDeclaration(node: FunctionDeclaration): void { if (produceDiagnostics) { - checkFunctionOrMethodDeclaration(node) || checkGrammarForGenerator(node); - + checkFunctionOrMethodDeclaration(node); + checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithCapturedNewTargetVariable(node, node.name); @@ -19447,14 +19441,15 @@ namespace ts { checkSourceElement(node.body); + const returnTypeNode = getEffectiveReturnTypeNode(node); if ((functionFlags & FunctionFlags.Generator) === 0) { // Async function or normal function - const returnOrPromisedType = node.type && (functionFlags & FunctionFlags.Async + const returnOrPromisedType = returnTypeNode && (functionFlags & FunctionFlags.Async ? checkAsyncFunctionReturnType(node) // Async function - : getTypeFromTypeNode(node.type)); // normal function + : getTypeFromTypeNode(returnTypeNode)); // normal function checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnOrPromisedType); } - if (produceDiagnostics && !node.type) { + if (produceDiagnostics && !returnTypeNode) { // Report an implicit any error if there is no body, no explicit return type, and node is not a private method // in an ambient context if (noImplicitAny && nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) { @@ -19559,9 +19554,7 @@ namespace ts { function errorUnusedLocal(node: Node, name: string) { if (isIdentifierThatStartsWithUnderScore(node)) { const declaration = getRootDeclaration(node.parent); - if (declaration.kind === SyntaxKind.VariableDeclaration && - (declaration.parent.parent.kind === SyntaxKind.ForInStatement || - declaration.parent.parent.kind === SyntaxKind.ForOfStatement)) { + if (declaration.kind === SyntaxKind.VariableDeclaration && isForInOrOfStatement(declaration.parent.parent)) { return; } } @@ -20254,7 +20247,7 @@ namespace ts { } } - function checkForInOrForOfVariableDeclaration(iterationStatement: ForInStatement | ForOfStatement): void { + function checkForInOrForOfVariableDeclaration(iterationStatement: ForInOrOfStatement): void { const variableDeclarationList = iterationStatement.initializer; // checkGrammarForInOrForOfStatement will check that there is exactly one declaration. if (variableDeclarationList.declarations.length >= 1) { @@ -20584,7 +20577,8 @@ namespace ts { } function isGetAccessorWithAnnotatedSetAccessor(node: FunctionLikeDeclaration) { - return !!(node.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(getDeclarationOfKind(node.symbol, SyntaxKind.SetAccessor))); + return node.kind === SyntaxKind.GetAccessor + && getEffectiveSetAccessorTypeAnnotationNode(getDeclarationOfKind(node.symbol, SyntaxKind.SetAccessor)) !== undefined; } function isUnwrappedReturnTypeVoidOrAny(func: FunctionLikeDeclaration, returnType: Type): boolean { @@ -20628,7 +20622,7 @@ namespace ts { error(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } - else if (func.type || isGetAccessorWithAnnotatedSetAccessor(func)) { + else if (getEffectiveReturnTypeNode(func) || isGetAccessorWithAnnotatedSetAccessor(func)) { if (functionFlags & FunctionFlags.Async) { // Async function const promisedType = getPromisedTypeOfPromise(returnType); const awaitedType = checkAwaitedType(exprType, node, Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member); @@ -21766,7 +21760,10 @@ namespace ts { } // Don't allow to re-export something with no value side when `--isolatedModules` is set. - if (node.kind === SyntaxKind.ExportSpecifier && compilerOptions.isolatedModules && !(target.flags & SymbolFlags.Value)) { + if (compilerOptions.isolatedModules + && node.kind === SyntaxKind.ExportSpecifier + && !(target.flags & SymbolFlags.Value) + && !isInAmbientContext(node)) { error(node, Diagnostics.Cannot_re_export_a_type_when_the_isolatedModules_flag_is_provided); } } @@ -22528,10 +22525,16 @@ namespace ts { } if (entityName.parent!.kind === SyntaxKind.JSDocParameterTag) { - const parameter = ts.getParameterFromJSDoc(entityName.parent as JSDocParameterTag); + const parameter = getParameterFromJSDoc(entityName.parent as JSDocParameterTag); return parameter && parameter.symbol; } + if (entityName.parent.kind === SyntaxKind.TypeParameter && entityName.parent.parent.kind === SyntaxKind.JSDocTemplateTag) { + Debug.assert(!isInJavaScriptFile(entityName)); // Otherwise `isDeclarationName` would have been true. + const typeParameter = getTypeParameterFromJsDoc(entityName.parent as TypeParameterDeclaration & { parent: JSDocTemplateTag }); + return typeParameter && typeParameter.symbol; + } + if (isPartOfExpression(entityName)) { if (nodeIsMissing(entityName)) { // Missing entity name. @@ -24224,7 +24227,7 @@ namespace ts { } } - function checkGrammarForInOrForOfStatement(forInOrOfStatement: ForInStatement | ForOfStatement): boolean { + function checkGrammarForInOrForOfStatement(forInOrOfStatement: ForInOrOfStatement): boolean { if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) { return true; } @@ -24792,13 +24795,9 @@ namespace ts { switch (name.parent.kind) { case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: - if ((name.parent as ImportOrExportSpecifier).propertyName) { - return true; - } - // falls through + return true; default: return isDeclarationName(name); - } } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 2488ad68101..a21c9bd5cd9 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -620,6 +620,12 @@ namespace ts { category: Diagnostics.Advanced_Options, description: Diagnostics.The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files }, + { + name: "noStrictGenericChecks", + type: "boolean", + category: Diagnostics.Advanced_Options, + description: Diagnostics.Disable_strict_checking_of_generic_signatures_in_function_types, + }, { // A list of plugins to load in the language service name: "plugins", diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 6ca99c2d086..d70369f4ab6 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2131,13 +2131,13 @@ namespace ts { export function getScriptKindFromFileName(fileName: string): ScriptKind { const ext = fileName.substr(fileName.lastIndexOf(".")); switch (ext.toLowerCase()) { - case ".js": + case Extension.Js: return ScriptKind.JS; - case ".jsx": + case Extension.Jsx: return ScriptKind.JSX; - case ".ts": + case Extension.Ts: return ScriptKind.TS; - case ".tsx": + case Extension.Tsx: return ScriptKind.TSX; default: return ScriptKind.Unknown; @@ -2147,10 +2147,10 @@ namespace ts { /** * List of supported extensions in order of file resolution precedence. */ - export const supportedTypeScriptExtensions = [".ts", ".tsx", ".d.ts"]; + export const supportedTypeScriptExtensions = [Extension.Ts, Extension.Tsx, Extension.Dts]; /** Must have ".d.ts" first because if ".ts" goes first, that will be detected as the extension instead of ".d.ts". */ - export const supportedTypescriptExtensionsForExtractExtension = [".d.ts", ".ts", ".tsx"]; - export const supportedJavascriptExtensions = [".js", ".jsx"]; + export const supportedTypescriptExtensionsForExtractExtension = [Extension.Dts, Extension.Ts, Extension.Tsx]; + export const supportedJavascriptExtensions = [Extension.Js, Extension.Jsx]; const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions); export function getSupportedExtensions(options?: CompilerOptions, extraFileExtensions?: JsFileExtensionInfo[]): string[] { @@ -2158,7 +2158,7 @@ namespace ts { if (!extraFileExtensions || extraFileExtensions.length === 0 || !needAllExtensions) { return needAllExtensions ? allSupportedExtensions : supportedTypeScriptExtensions; } - const extensions = allSupportedExtensions.slice(0); + const extensions: string[] = allSupportedExtensions.slice(0); for (const extInfo of extraFileExtensions) { if (extensions.indexOf(extInfo.extension) === -1) { extensions.push(extInfo.extension); @@ -2237,7 +2237,7 @@ namespace ts { } } - const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"]; + const extensionsToRemove = [Extension.Dts, Extension.Ts, Extension.Js, Extension.Tsx, Extension.Jsx]; export function removeFileExtension(path: string): string { for (const ext of extensionsToRemove) { const extensionless = tryRemoveExtension(path, ext); @@ -2491,7 +2491,7 @@ namespace ts { /** True if an extension is one of the supported TypeScript extensions. */ export function extensionIsTypeScript(ext: Extension): boolean { - return ext <= Extension.LastTypeScriptExtension; + return ext === Extension.Ts || ext === Extension.Tsx || ext === Extension.Dts; } /** @@ -2506,21 +2506,7 @@ namespace ts { Debug.fail(`File ${path} has unknown extension.`); } export function tryGetExtensionFromPath(path: string): Extension | undefined { - if (fileExtensionIs(path, ".d.ts")) { - return Extension.Dts; - } - if (fileExtensionIs(path, ".ts")) { - return Extension.Ts; - } - if (fileExtensionIs(path, ".tsx")) { - return Extension.Tsx; - } - if (fileExtensionIs(path, ".js")) { - return Extension.Js; - } - if (fileExtensionIs(path, ".jsx")) { - return Extension.Jsx; - } + return find(supportedTypescriptExtensionsForExtractExtension, e => fileExtensionIs(path, e)) || find(supportedJavascriptExtensions, e => fileExtensionIs(path, e)); } export function isCheckJsEnabledForFile(sourceFile: SourceFile, compilerOptions: CompilerOptions) { diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 987157843b6..007620ad510 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -596,7 +596,7 @@ namespace ts { currentIdentifiers = node.identifiers; isCurrentFileExternalModule = isExternalModule(node); enclosingDeclaration = node; - emitDetachedComments(currentText, currentLineMap, writer, writeCommentRange, node, newLine, /*removeComents*/ true); + emitDetachedComments(currentText, currentLineMap, writer, writeCommentRange, node, newLine, /*removeComments*/ true); emitLines(node.statements); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 70efe50143e..eda408c03e5 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3278,6 +3278,10 @@ "category": "Message", "code": 6184 }, + "Disable strict checking of generic signatures in function types.": { + "category": "Message", + "code": 6185 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 4c6616c36d4..4ea590977e1 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -815,15 +815,15 @@ namespace ts { switch (extensions) { case Extensions.DtsOnly: - return tryExtension(".d.ts", Extension.Dts); + return tryExtension(Extension.Dts); case Extensions.TypeScript: - return tryExtension(".ts", Extension.Ts) || tryExtension(".tsx", Extension.Tsx) || tryExtension(".d.ts", Extension.Dts); + return tryExtension(Extension.Ts) || tryExtension(Extension.Tsx) || tryExtension(Extension.Dts); case Extensions.JavaScript: - return tryExtension(".js", Extension.Js) || tryExtension(".jsx", Extension.Jsx); + return tryExtension(Extension.Js) || tryExtension(Extension.Jsx); } - function tryExtension(ext: string, extension: Extension): Resolved | undefined { - const path = tryFile(candidate + ext, failedLookupLocations, onlyRecordFailures, state); + function tryExtension(extension: Extension): Resolved | undefined { + const path = tryFile(candidate + extension, failedLookupLocations, onlyRecordFailures, state); return path && { path, extension }; } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e2e541239ef..75186eca2c1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -15,7 +15,7 @@ namespace ts { else if (kind === SyntaxKind.Identifier) { return new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, pos, end); } - else if (kind < SyntaxKind.FirstNode) { + else if (!isNodeKind(kind)) { return new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind, pos, end); } else { @@ -764,7 +764,7 @@ namespace ts { sourceFile.languageVersion = languageVersion; sourceFile.fileName = normalizePath(fileName); sourceFile.languageVariant = getLanguageVariant(scriptKind); - sourceFile.isDeclarationFile = fileExtensionIs(sourceFile.fileName, ".d.ts"); + sourceFile.isDeclarationFile = fileExtensionIs(sourceFile.fileName, Extension.Dts); sourceFile.scriptKind = scriptKind; return sourceFile; @@ -1103,7 +1103,7 @@ namespace ts { pos = scanner.getStartPos(); } - return kind >= SyntaxKind.FirstNode ? new NodeConstructor(kind, pos, pos) : + return isNodeKind(kind) ? new NodeConstructor(kind, pos, pos) : kind === SyntaxKind.Identifier ? new IdentifierConstructor(kind, pos, pos) : new TokenConstructor(kind, pos, pos); } @@ -6851,7 +6851,7 @@ namespace ts { jsDocNamespaceNode.flags |= flags; jsDocNamespaceNode.name = typeNameOrNamespaceName; jsDocNamespaceNode.body = parseJSDocTypeNameWithNamespace(NodeFlags.NestedNamespace); - return jsDocNamespaceNode; + return finishNode(jsDocNamespaceNode); } if (typeNameOrNamespaceName && flags & NodeFlags.NestedNamespace) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 3ca9d03466e..cc6ae1a5813 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1495,7 +1495,7 @@ namespace ts { } const sourceFileWithAddedExtension = forEach(supportedExtensions, extension => getSourceFile(fileName + extension)); - if (fail && !sourceFileWithAddedExtension) fail(Diagnostics.File_0_not_found, fileName + ".ts"); + if (fail && !sourceFileWithAddedExtension) fail(Diagnostics.File_0_not_found, fileName + Extension.Ts); return sourceFileWithAddedExtension; } } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 1abebe937e6..cd14f3b2801 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -35,6 +35,10 @@ namespace ts { getDirectories(path: string): string[]; readDirectory(path: string, extensions?: string[], exclude?: string[], include?: string[]): string[]; getModifiedTime?(path: string): Date; + /** + * This should be cryptographically secure. + * A good implementation is node.js' `crypto.createHash`. (https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm) + */ createHash?(data: string): string; getMemoryUsage?(): number; exit(exitCode?: number): void; diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index f0c827d8396..bfd3360e885 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -239,7 +239,7 @@ namespace ts { function hoistVariableDeclaration(name: Identifier): void { Debug.assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization."); Debug.assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed."); - const decl = createVariableDeclaration(name); + const decl = setEmitFlags(createVariableDeclaration(name), EmitFlags.NoNestedSourceMaps); if (!lexicalEnvironmentVariableDeclarations) { lexicalEnvironmentVariableDeclarations = [decl]; } diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index 9aadd6bc686..d0049e72f0b 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -640,10 +640,13 @@ namespace ts { return undefined; } - return createStatement( - inlineExpressions( - map(variables, transformInitializedVariable) - ) + return setSourceMapRange( + createStatement( + inlineExpressions( + map(variables, transformInitializedVariable) + ) + ), + node ); } } @@ -1281,9 +1284,12 @@ namespace ts { } function transformInitializedVariable(node: VariableDeclaration) { - return createAssignment( - getSynthesizedClone(node.name), - visitNode(node.initializer, visitor, isExpression) + return setSourceMapRange( + createAssignment( + setSourceMapRange(getSynthesizedClone(node.name), node.name), + visitNode(node.initializer, visitor, isExpression) + ), + node ); } diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 834c7326e22..637cfd0f165 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -662,6 +662,10 @@ namespace ts { } } +if (ts.Debug.isDebugging) { + ts.Debug.enableDebugInfo(); +} + if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) { ts.sys.tryEnableSourceMapsForHost(); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b0414a98ecb..439091cece0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1708,6 +1708,8 @@ namespace ts { incrementor?: Expression; } + export type ForInOrOfStatement = ForInStatement | ForOfStatement; + export interface ForInStatement extends IterationStatement { kind: SyntaxKind.ForInStatement; initializer: ForInitializer; @@ -1797,7 +1799,7 @@ namespace ts { block: Block; } - export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration; + export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; export interface ClassLikeDeclaration extends NamedDeclaration { name?: Identifier; @@ -3522,6 +3524,7 @@ namespace ts { noImplicitAny?: boolean; // Always combine with strict property noImplicitReturns?: boolean; noImplicitThis?: boolean; // Always combine with strict property + noStrictGenericChecks?: boolean; noUnusedLocals?: boolean; noUnusedParameters?: boolean; noImplicitUseStrict?: boolean; @@ -3881,13 +3884,12 @@ namespace ts { extension: Extension; } - export enum Extension { - Ts, - Tsx, - Dts, - Js, - Jsx, - LastTypeScriptExtension = Dts + export const enum Extension { + Ts = ".ts", + Tsx = ".tsx", + Dts = ".d.ts", + Js = ".js", + Jsx = ".jsx" } export interface ResolvedModuleWithFailedLookupLocations { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 77f1e43c9cb..3833fc30875 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1448,7 +1448,7 @@ namespace ts { return node && firstOrUndefined(getJSDocTags(node, kind)); } - export function getJSDocs(node: Node): (JSDoc | JSDocTag)[] { + export function getJSDocs(node: Node): (JSDoc | JSDocTag)[] { if (isJSDocTypedefTag(node)) { return [node.parent]; } @@ -1546,6 +1546,12 @@ namespace ts { p.name.kind === SyntaxKind.Identifier && p.name.text === name); } + export function getTypeParameterFromJsDoc(node: TypeParameterDeclaration & { parent: JSDocTemplateTag }): TypeParameterDeclaration | undefined { + const name = node.name.text; + const { typeParameters } = (node.parent.parent.parent as ts.SignatureDeclaration | ts.InterfaceDeclaration | ts.ClassDeclaration); + return find(typeParameters, p => p.name.text === name); + } + export function getJSDocType(node: Node): JSDocType { let tag: JSDocTypeTag | JSDocParameterTag = getFirstJSDocTag(node, SyntaxKind.JSDocTypeTag) as JSDocTypeTag; if (!tag && node.kind === SyntaxKind.Parameter) { @@ -1570,6 +1576,11 @@ namespace ts { return getFirstJSDocTag(node, SyntaxKind.JSDocReturnTag) as JSDocReturnTag; } + export function getJSDocReturnType(node: Node): JSDocType { + const returnTag = getJSDocReturnTag(node); + return returnTag && returnTag.typeExpression && returnTag.typeExpression.type; + } + export function getJSDocTemplateTag(node: Node): JSDocTemplateTag { return getFirstJSDocTag(node, SyntaxKind.JSDocTemplateTag) as JSDocTemplateTag; } @@ -1616,7 +1627,7 @@ namespace ts { return unaryOperator === SyntaxKind.PlusPlusToken || unaryOperator === SyntaxKind.MinusMinusToken ? AssignmentKind.Compound : AssignmentKind.None; case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: - return (parent).initializer === node ? AssignmentKind.Definite : AssignmentKind.None; + return (parent).initializer === node ? AssignmentKind.Definite : AssignmentKind.None; case SyntaxKind.ParenthesizedExpression: case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.SpreadElement: @@ -2490,7 +2501,7 @@ namespace ts { const path = outputDir ? getSourceFilePathInNewDir(sourceFile, host, outputDir) : sourceFile.fileName; - return removeFileExtension(path) + ".d.ts"; + return removeFileExtension(path) + Extension.Dts; } export interface EmitFileNames { @@ -2549,7 +2560,7 @@ namespace ts { if (sourceFiles.length) { const jsFilePath = options.outFile || options.out; const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options); - const declarationFilePath = options.declaration ? removeFileExtension(jsFilePath) + ".d.ts" : ""; + const declarationFilePath = options.declaration ? removeFileExtension(jsFilePath) + Extension.Dts : ""; action({ jsFilePath, sourceMapFilePath, declarationFilePath }, createBundle(sourceFiles), emitOnlyDtsFiles); } } @@ -2570,19 +2581,19 @@ namespace ts { // JavaScript files are always LanguageVariant.JSX, as JSX syntax is allowed in .js files also. // So for JavaScript files, '.jsx' is only emitted if the input was '.jsx', and JsxEmit.Preserve. // For TypeScript, the only time to emit with a '.jsx' extension, is on JSX input, and JsxEmit.Preserve - function getOutputExtension(sourceFile: SourceFile, options: CompilerOptions): string { + function getOutputExtension(sourceFile: SourceFile, options: CompilerOptions): Extension { if (options.jsx === JsxEmit.Preserve) { if (isSourceFileJavaScript(sourceFile)) { - if (fileExtensionIs(sourceFile.fileName, ".jsx")) { - return ".jsx"; + if (fileExtensionIs(sourceFile.fileName, Extension.Jsx)) { + return Extension.Jsx; } } else if (sourceFile.languageVariant === LanguageVariant.JSX) { // TypeScript source file preserving JSX syntax - return ".jsx"; + return Extension.Jsx; } } - return ".js"; + return Extension.Js; } export function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) { @@ -2615,14 +2626,19 @@ namespace ts { }); } - /** Get the type annotaion for the value parameter. */ - export function getSetAccessorTypeAnnotationNode(accessor: SetAccessorDeclaration): TypeNode { + function getSetAccessorValueParameter(accessor: SetAccessorDeclaration): ParameterDeclaration | undefined { if (accessor && accessor.parameters.length > 0) { const hasThis = accessor.parameters.length === 2 && parameterIsThisKeyword(accessor.parameters[0]); - return accessor.parameters[hasThis ? 1 : 0].type; + return accessor.parameters[hasThis ? 1 : 0]; } } + /** Get the type annotation for the value parameter. */ + export function getSetAccessorTypeAnnotationNode(accessor: SetAccessorDeclaration): TypeNode { + const parameter = getSetAccessorValueParameter(accessor); + return parameter && parameter.type; + } + export function getThisParameter(signature: SignatureDeclaration): ParameterDeclaration | undefined { if (signature.parameters.length) { const thisParameter = signature.parameters[0]; @@ -2701,6 +2717,55 @@ namespace ts { }; } + /** + * Gets the effective type annotation of a variable, parameter, or property. If the node was + * parsed in a JavaScript file, gets the type annotation from JSDoc. + */ + export function getEffectiveTypeAnnotationNode(node: VariableLikeDeclaration): TypeNode { + if (node.type) { + return node.type; + } + if (node.flags & NodeFlags.JavaScriptFile) { + return getJSDocType(node); + } + } + + /** + * Gets the effective return type annotation of a signature. If the node was parsed in a + * JavaScript file, gets the return type annotation from JSDoc. + */ + export function getEffectiveReturnTypeNode(node: SignatureDeclaration): TypeNode { + if (node.type) { + return node.type; + } + if (node.flags & NodeFlags.JavaScriptFile) { + return getJSDocReturnType(node); + } + } + + /** + * Gets the effective type parameters. If the node was parsed in a + * JavaScript file, gets the type parameters from the `@template` tag from JSDoc. + */ + export function getEffectiveTypeParameterDeclarations(node: DeclarationWithTypeParameters): TypeParameterDeclaration[] { + if (node.typeParameters) { + return node.typeParameters; + } + if (node.flags & NodeFlags.JavaScriptFile) { + const templateTag = getJSDocTemplateTag(node); + return templateTag && templateTag.typeParameters; + } + } + + /** + * Gets the effective type annotation of the value parameter of a set accessor. If the node + * was parsed in a JavaScript file, gets the type annotation from JSDoc. + */ + export function getEffectiveSetAccessorTypeAnnotationNode(node: SetAccessorDeclaration): TypeNode { + const parameter = getSetAccessorValueParameter(node); + return parameter && getEffectiveTypeAnnotationNode(parameter); + } + export function emitNewLineBeforeLeadingComments(lineMap: number[], writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) { emitNewLineBeforeLeadingCommentsOfPosition(lineMap, writer, node.pos, leadingComments); } @@ -4047,7 +4112,7 @@ namespace ts { // Signature elements - export function isTypeParameter(node: Node): node is TypeParameterDeclaration { + export function isTypeParameterDeclaration(node: Node): node is TypeParameterDeclaration { return node.kind === SyntaxKind.TypeParameter; } @@ -4670,6 +4735,16 @@ namespace ts { // All node tests in the following list should *not* reference parent pointers so that // they may be used with transformations. namespace ts { + /* @internal */ + export function isNode(node: Node) { + return isNodeKind(node.kind); + } + + /* @internal */ + export function isNodeKind(kind: SyntaxKind) { + return kind >= SyntaxKind.FirstNode; + } + /** * True if node is of some token syntax kind. * For example, this is true for an IfKeyword but not for an IfStatement. @@ -5091,6 +5166,11 @@ namespace ts { return false; } + /* @internal */ + export function isForInOrOfStatement(node: Node): node is ForInOrOfStatement { + return node.kind === SyntaxKind.ForInStatement || node.kind === SyntaxKind.ForOfStatement; + } + // Element /* @internal */ @@ -5219,6 +5299,10 @@ namespace ts { /* @internal */ export function isDeclaration(node: Node): node is NamedDeclaration { + if (node.kind === SyntaxKind.TypeParameter) { + return node.parent.kind !== SyntaxKind.JSDocTemplateTag || isInJavaScriptFile(node); + } + return isDeclarationKind(node.kind); } @@ -5308,6 +5392,11 @@ namespace ts { return node.kind >= SyntaxKind.FirstJSDocNode && node.kind <= SyntaxKind.LastJSDocNode; } + /** True if node is of a kind that may contain comment text. */ + export function isJSDocCommentContainingNode(node: Node): boolean { + return node.kind === SyntaxKind.JSDocComment || isJSDocTag(node); + } + // TODO: determine what this does before making it public. /* @internal */ export function isJSDocTag(node: Node): boolean { diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index fc3b9c784cc..391fa88c79d 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -275,7 +275,7 @@ namespace ts { case SyntaxKind.MethodSignature: return updateMethodSignature(node, - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).parameters, visitor, isParameterDeclaration), visitNode((node).type, visitor, isTypeNode), visitNode((node).name, visitor, isPropertyName), @@ -288,7 +288,7 @@ namespace ts { visitNode((node).asteriskToken, tokenVisitor, isToken), visitNode((node).name, visitor, isPropertyName), visitNode((node).questionToken, tokenVisitor, isToken), - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), visitParameterList((node).parameters, visitor, context, nodesVisitor), visitNode((node).type, visitor, isTypeNode), visitFunctionBody((node).body, visitor, context)); @@ -319,13 +319,13 @@ namespace ts { case SyntaxKind.CallSignature: return updateCallSignature(node, - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).parameters, visitor, isParameterDeclaration), visitNode((node).type, visitor, isTypeNode)); case SyntaxKind.ConstructSignature: return updateConstructSignature(node, - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).parameters, visitor, isParameterDeclaration), visitNode((node).type, visitor, isTypeNode)); @@ -350,13 +350,13 @@ namespace ts { case SyntaxKind.FunctionType: return updateFunctionTypeNode(node, - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).parameters, visitor, isParameterDeclaration), visitNode((node).type, visitor, isTypeNode)); case SyntaxKind.ConstructorType: return updateConstructorTypeNode(node, - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).parameters, visitor, isParameterDeclaration), visitNode((node).type, visitor, isTypeNode)); @@ -400,7 +400,7 @@ namespace ts { case SyntaxKind.MappedType: return updateMappedTypeNode((node), visitNode((node).readonlyToken, tokenVisitor, isToken), - visitNode((node).typeParameter, visitor, isTypeParameter), + visitNode((node).typeParameter, visitor, isTypeParameterDeclaration), visitNode((node).questionToken, tokenVisitor, isToken), visitNode((node).type, visitor, isTypeNode)); @@ -476,7 +476,7 @@ namespace ts { nodesVisitor((node).modifiers, visitor, isModifier), visitNode((node).asteriskToken, tokenVisitor, isToken), visitNode((node).name, visitor, isIdentifier), - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), visitParameterList((node).parameters, visitor, context, nodesVisitor), visitNode((node).type, visitor, isTypeNode), visitFunctionBody((node).body, visitor, context)); @@ -484,7 +484,7 @@ namespace ts { case SyntaxKind.ArrowFunction: return updateArrowFunction(node, nodesVisitor((node).modifiers, visitor, isModifier), - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), visitParameterList((node).parameters, visitor, context, nodesVisitor), visitNode((node).type, visitor, isTypeNode), visitFunctionBody((node).body, visitor, context)); @@ -543,7 +543,7 @@ namespace ts { return updateClassExpression(node, nodesVisitor((node).modifiers, visitor, isModifier), visitNode((node).name, visitor, isIdentifier), - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).heritageClauses, visitor, isHeritageClause), nodesVisitor((node).members, visitor, isClassElement)); @@ -676,7 +676,7 @@ namespace ts { nodesVisitor((node).modifiers, visitor, isModifier), visitNode((node).asteriskToken, tokenVisitor, isToken), visitNode((node).name, visitor, isIdentifier), - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), visitParameterList((node).parameters, visitor, context, nodesVisitor), visitNode((node).type, visitor, isTypeNode), visitFunctionBody((node).body, visitor, context)); @@ -686,7 +686,7 @@ namespace ts { nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), visitNode((node).name, visitor, isIdentifier), - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).heritageClauses, visitor, isHeritageClause), nodesVisitor((node).members, visitor, isClassElement)); @@ -695,7 +695,7 @@ namespace ts { nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), visitNode((node).name, visitor, isIdentifier), - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor((node).heritageClauses, visitor, isHeritageClause), nodesVisitor((node).members, visitor, isTypeElement)); @@ -704,7 +704,7 @@ namespace ts { nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), visitNode((node).name, visitor, isIdentifier), - nodesVisitor((node).typeParameters, visitor, isTypeParameter), + nodesVisitor((node).typeParameters, visitor, isTypeParameterDeclaration), visitNode((node).type, visitor, isTypeNode)); case SyntaxKind.EnumDeclaration: @@ -1198,9 +1198,9 @@ namespace ts { case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: - result = reduceNode((node).initializer, cbNode, result); - result = reduceNode((node).expression, cbNode, result); - result = reduceNode((node).statement, cbNode, result); + result = reduceNode((node).initializer, cbNode, result); + result = reduceNode((node).expression, cbNode, result); + result = reduceNode((node).statement, cbNode, result); break; case SyntaxKind.ReturnStatement: @@ -1517,35 +1517,7 @@ namespace ts { } export namespace Debug { - if (isDebugging) { - // Add additional properties in debug mode to assist with debugging. - Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, { - "__debugFlags": { get(this: Symbol) { return formatSymbolFlags(this.flags); } } - }); - - Object.defineProperties(objectAllocator.getTypeConstructor().prototype, { - "__debugFlags": { get(this: Type) { return formatTypeFlags(this.flags); } }, - "__debugObjectFlags": { get(this: Type) { return this.flags & TypeFlags.Object ? formatObjectFlags((this).objectFlags) : ""; } }, - "__debugTypeToString": { value(this: Type) { return this.checker.typeToString(this); } }, - }); - - for (const ctor of [objectAllocator.getNodeConstructor(), objectAllocator.getIdentifierConstructor(), objectAllocator.getTokenConstructor(), objectAllocator.getSourceFileConstructor()]) { - if (!ctor.prototype.hasOwnProperty("__debugKind")) { - Object.defineProperties(ctor.prototype, { - "__debugKind": { get(this: Node) { return formatSyntaxKind(this.kind); } }, - "__debugModifierFlags": { get(this: Node) { return formatModifierFlags(getModifierFlagsNoCache(this)); } }, - "__debugTransformFlags": { get(this: Node) { return formatTransformFlags(this.transformFlags); } }, - "__debugEmitFlags": { get(this: Node) { return formatEmitFlags(getEmitFlags(this)); } }, - "__debugGetText": { value(this: Node, includeTrivia?: boolean) { - if (nodeIsSynthesized(this)) return ""; - const parseNode = getParseTreeNode(this); - const sourceFile = parseNode && getSourceFileOfNode(parseNode); - return sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; - } } - }); - } - } - } + let isDebugInfoEnabled = false; export const failBadSyntaxKind = shouldAssert(AssertionLevel.Normal) ? (node: Node, message?: string): void => fail( @@ -1592,5 +1564,51 @@ namespace ts { () => `Node ${formatSyntaxKind(node.kind)} was unexpected'.`, assertMissingNode) : noop; + + /** + * Injects debug information into frequently used types. + */ + export function enableDebugInfo() { + if (isDebugInfoEnabled) return; + + // Add additional properties in debug mode to assist with debugging. + Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, { + "__debugFlags": { get(this: Symbol) { return formatSymbolFlags(this.flags); } } + }); + + Object.defineProperties(objectAllocator.getTypeConstructor().prototype, { + "__debugFlags": { get(this: Type) { return formatTypeFlags(this.flags); } }, + "__debugObjectFlags": { get(this: Type) { return this.flags & TypeFlags.Object ? formatObjectFlags((this).objectFlags) : ""; } }, + "__debugTypeToString": { value(this: Type) { return this.checker.typeToString(this); } }, + }); + + const nodeConstructors = [ + objectAllocator.getNodeConstructor(), + objectAllocator.getIdentifierConstructor(), + objectAllocator.getTokenConstructor(), + objectAllocator.getSourceFileConstructor() + ]; + + for (const ctor of nodeConstructors) { + if (!ctor.prototype.hasOwnProperty("__debugKind")) { + Object.defineProperties(ctor.prototype, { + "__debugKind": { get(this: Node) { return formatSyntaxKind(this.kind); } }, + "__debugModifierFlags": { get(this: Node) { return formatModifierFlags(getModifierFlagsNoCache(this)); } }, + "__debugTransformFlags": { get(this: Node) { return formatTransformFlags(this.transformFlags); } }, + "__debugEmitFlags": { get(this: Node) { return formatEmitFlags(getEmitFlags(this)); } }, + "__debugGetText": { + value(this: Node, includeTrivia?: boolean) { + if (nodeIsSynthesized(this)) return ""; + const parseNode = getParseTreeNode(this); + const sourceFile = parseNode && getSourceFileOfNode(parseNode); + return sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; + } + } + }); + } + } + + isDebugInfoEnabled = true; + } } } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index d0eee02efd7..ff418ab34de 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -90,7 +90,7 @@ class CompilerBaselineRunner extends RunnerBase { } lastUnit = units[units.length - 1]; - hasNonDtsFiles = ts.forEach(units, unit => !ts.fileExtensionIs(unit.name, ".d.ts")); + hasNonDtsFiles = ts.forEach(units, unit => !ts.fileExtensionIs(unit.name, ts.Extension.Dts)); // We need to assemble the list of input files for the compiler and other related files on the 'filesystem' (ie in a multi-file test) // If the last file in a test uses require or a triple slash reference we'll assume all other files will be brought in via references, // otherwise, assume all files are just meant to be in the same compilation session without explicit references to one another. diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index f40d63709cb..ceeec7f9b9c 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -536,11 +536,16 @@ namespace FourSlash { Harness.IO.log("Unexpected error(s) found. Error list is:"); } - for (const { start, length, messageText } of errors) { - Harness.IO.log(" minChar: " + start + - ", limChar: " + (start + length) + + for (const { start, length, messageText, file } of errors) { + Harness.IO.log(" from: " + showPosition(file, start) + + ", to: " + showPosition(file, start + length) + ", message: " + ts.flattenDiagnosticMessageText(messageText, Harness.IO.newLine()) + "\n"); } + + function showPosition(file: ts.SourceFile, pos: number) { + const { line, character } = ts.getLineAndCharacterOfPosition(file, pos); + return `${line}:${character}`; + } } public verifyNoErrors() { @@ -1459,7 +1464,7 @@ namespace FourSlash { let baselineFile = this.testData.globalOptions[metadataOptionNames.baselineFile]; if (!baselineFile) { baselineFile = this.activeFile.fileName.replace(this.basePath + "/breakpointValidation", "bpSpan"); - baselineFile = baselineFile.replace(".ts", ".baseline"); + baselineFile = baselineFile.replace(ts.Extension.Ts, ".baseline"); } Harness.Baseline.runBaseline( @@ -1529,7 +1534,7 @@ namespace FourSlash { public baselineQuickInfo() { let baselineFile = this.testData.globalOptions[metadataOptionNames.baselineFile]; if (!baselineFile) { - baselineFile = ts.getBaseFileName(this.activeFile.fileName).replace(".ts", ".baseline"); + baselineFile = ts.getBaseFileName(this.activeFile.fileName).replace(ts.Extension.Ts, ".baseline"); } Harness.Baseline.runBaseline( @@ -2671,6 +2676,13 @@ namespace FourSlash { this.rangesByText().forEach(ranges => this.verifyRangesAreDocumentHighlights(ranges)); } + public verifyDocumentHighlightsOf(startRange: Range, ranges: Range[]) { + ts.Debug.assert(ts.contains(ranges, startRange)); + const fileNames = unique(ranges, range => range.fileName); + this.goToRangeStart(startRange); + this.verifyDocumentHighlights(ranges, fileNames); + } + public verifyRangesAreDocumentHighlights(ranges?: Range[]) { ranges = ranges || this.getRanges(); const fileNames = unique(ranges, range => range.fileName); @@ -3885,6 +3897,10 @@ namespace FourSlashInterface { this.state.verifyRangesWithSameTextAreDocumentHighlights(); } + public documentHighlightsOf(startRange: FourSlash.Range, ranges: FourSlash.Range[]) { + this.state.verifyDocumentHighlightsOf(startRange, ranges); + } + public completionEntryDetailIs(entryName: string, text: string, documentation?: string, kind?: string, tags?: ts.JSDocTagInfo[]) { this.state.verifyCompletionEntryDetails(entryName, text, documentation, kind, tags); } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index d61ba6e953b..e944e68f11e 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1053,7 +1053,7 @@ namespace Harness { ]; let optionsIndex: ts.Map; - function getCommandLineOption(name: string): ts.CommandLineOption { + function getCommandLineOption(name: string): ts.CommandLineOption | undefined { if (!optionsIndex) { optionsIndex = ts.createMap(); const optionDeclarations = harnessOptionDeclarations.concat(ts.optionDeclarations); @@ -1249,7 +1249,7 @@ namespace Harness { sourceFileName = outFile; } - const dTsFileName = ts.removeFileExtension(sourceFileName) + ".d.ts"; + const dTsFileName = ts.removeFileExtension(sourceFileName) + ts.Extension.Dts; return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined); } @@ -1465,7 +1465,7 @@ namespace Harness { // When calling this function from rwc-runner, the baselinePath will have no extension. // As rwc test- file is stored in json which ".json" will get stripped off. // When calling this function from compiler-runner, the baselinePath will then has either ".ts" or ".tsx" extension - const outputFileName = ts.endsWith(baselinePath, ".ts") || ts.endsWith(baselinePath, ".tsx") ? + const outputFileName = ts.endsWith(baselinePath, ts.Extension.Ts) || ts.endsWith(baselinePath, ts.Extension.Tsx) ? baselinePath.replace(/\.tsx?/, fullExtension) : baselinePath.concat(fullExtension); Harness.Baseline.runBaseline(outputFileName, () => fullBaseLine, opts); } @@ -1563,7 +1563,7 @@ namespace Harness { } // check js output - Harness.Baseline.runBaseline(baselinePath.replace(/\.tsx?/, ".js"), () => { + Harness.Baseline.runBaseline(baselinePath.replace(/\.tsx?/, ts.Extension.Js), () => { let tsCode = ""; const tsSources = otherFiles.concat(toBeCompiled); if (tsSources.length > 1) { @@ -1651,22 +1651,22 @@ namespace Harness { } export function isTS(fileName: string) { - return ts.endsWith(fileName, ".ts"); + return ts.endsWith(fileName, ts.Extension.Ts); } export function isTSX(fileName: string) { - return ts.endsWith(fileName, ".tsx"); + return ts.endsWith(fileName, ts.Extension.Tsx); } export function isDTS(fileName: string) { - return ts.endsWith(fileName, ".d.ts"); + return ts.endsWith(fileName, ts.Extension.Dts); } export function isJS(fileName: string) { - return ts.endsWith(fileName, ".js"); + return ts.endsWith(fileName, ts.Extension.Js); } export function isJSX(fileName: string) { - return ts.endsWith(fileName, ".jsx"); + return ts.endsWith(fileName, ts.Extension.Jsx); } export function isJSMap(fileName: string) { @@ -1973,7 +1973,7 @@ namespace Harness { export function isDefaultLibraryFile(filePath: string): boolean { // We need to make sure that the filePath is prefixed with "lib." not just containing "lib." and end with ".d.ts" const fileName = ts.getBaseFileName(ts.normalizeSlashes(filePath)); - return ts.startsWith(fileName, "lib.") && ts.endsWith(fileName, ".d.ts"); + return ts.startsWith(fileName, "lib.") && ts.endsWith(fileName, ts.Extension.Dts); } export function isBuiltFile(filePath: string): boolean { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 132db1e53eb..774c43556ca 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -731,7 +731,7 @@ namespace Harness.LanguageService { } createHash(s: string) { - return s; + return mockHash(s); } require(_initialDir: string, _moduleName: string): ts.server.RequireResult { @@ -856,4 +856,8 @@ namespace Harness.LanguageService { getClassifier(): ts.Classifier { throw new Error("getClassifier is not available using the server interface."); } getPreProcessedFileInfo(): ts.PreProcessedFileInfo { throw new Error("getPreProcessedFileInfo is not available using the server interface."); } } + + export function mockHash(s: string): string { + return `hash-${s}`; + } } diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 28d59fe35bd..5d4d5a41f3a 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -325,8 +325,8 @@ class ProjectRunner extends RunnerBase { // we need to instead create files that can live in the project reference folder // but make sure extension of these files matches with the fileName the compiler asked to write diskRelativeName = "diskFile" + nonSubfolderDiskFiles + - (Harness.Compiler.isDTS(fileName) ? ".d.ts" : - Harness.Compiler.isJS(fileName) ? ".js" : ".js.map"); + (Harness.Compiler.isDTS(fileName) ? ts.Extension.Dts : + Harness.Compiler.isJS(fileName) ? ts.Extension.Js : ".js.map"); nonSubfolderDiskFiles++; } @@ -386,14 +386,14 @@ class ProjectRunner extends RunnerBase { emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName); } - const outputDtsFileName = emitOutputFilePathWithoutExtension + ".d.ts"; + const outputDtsFileName = emitOutputFilePathWithoutExtension + ts.Extension.Dts; const file = findOutputDtsFile(outputDtsFileName); if (file) { allInputFiles.unshift(file); } } else { - const outputDtsFileName = ts.removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ".d.ts"; + const outputDtsFileName = ts.removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ts.Extension.Dts; const outputDtsFile = findOutputDtsFile(outputDtsFileName); if (!ts.contains(allInputFiles, outputDtsFile)) { allInputFiles.unshift(outputDtsFile); diff --git a/src/harness/runner.ts b/src/harness/runner.ts index 3ad6269e52f..4653e440f11 100644 --- a/src/harness/runner.ts +++ b/src/harness/runner.ts @@ -222,6 +222,10 @@ if (taskConfigsFolder) { } } else { + if (ts.Debug.isDebugging) { + ts.Debug.enableDebugInfo(); + } + runTests(runners); } if (!runUnitTests) { diff --git a/src/harness/unittests/cachingInServerLSHost.ts b/src/harness/unittests/cachingInServerLSHost.ts index 1b87fc848b5..9bb264b2637 100644 --- a/src/harness/unittests/cachingInServerLSHost.ts +++ b/src/harness/unittests/cachingInServerLSHost.ts @@ -47,7 +47,7 @@ namespace ts { clearTimeout, setImmediate: typeof setImmediate !== "undefined" ? setImmediate : action => setTimeout(action, 0), clearImmediate: typeof clearImmediate !== "undefined" ? clearImmediate : clearTimeout, - createHash: s => s + createHash: Harness.LanguageService.mockHash, }; } diff --git a/src/harness/unittests/compileOnSave.ts b/src/harness/unittests/compileOnSave.ts index eaab86b4ebc..7e262a1b257 100644 --- a/src/harness/unittests/compileOnSave.ts +++ b/src/harness/unittests/compileOnSave.ts @@ -513,7 +513,7 @@ namespace ts.projectSystem { const lines = ["var x = 1;", "var y = 2;"]; const path = "/a/app"; const f = { - path: path + ".ts", + path: path + ts.Extension.Ts, content: lines.join(newLine) }; const host = createServerHost([f], { newLine }); @@ -530,7 +530,7 @@ namespace ts.projectSystem { command: "compileOnSaveEmitFile", arguments: { file: f.path } }); - const emitOutput = host.readFile(path + ".js"); + const emitOutput = host.readFile(path + ts.Extension.Js); assert.equal(emitOutput, f.content + newLine, "content of emit output should be identical with the input + newline"); } }); diff --git a/src/harness/unittests/moduleResolution.ts b/src/harness/unittests/moduleResolution.ts index a4220f50321..87ec4ea8149 100644 --- a/src/harness/unittests/moduleResolution.ts +++ b/src/harness/unittests/moduleResolution.ts @@ -5,7 +5,7 @@ namespace ts { if (!expected === !actual) { if (expected) { assert.isTrue(expected.resolvedFileName === actual.resolvedFileName, `'resolvedFileName': expected '${expected.resolvedFileName}' to be equal to '${actual.resolvedFileName}'`); - assert.isTrue(expected.extension === actual.extension, `'ext': expected '${Extension[expected.extension]}' to be equal to '${Extension[actual.extension]}'`); + assert.isTrue(expected.extension === actual.extension, `'ext': expected '${expected.extension}' to be equal to '${actual.extension}'`); assert.isTrue(expected.isExternalLibraryImport === actual.isExternalLibraryImport, `'isExternalLibraryImport': expected '${expected.isExternalLibraryImport}' to be equal to '${actual.isExternalLibraryImport}'`); } return true; diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index efc769efeca..067cd351ec7 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -25,7 +25,7 @@ namespace ts.server { clearTimeout: noop, setImmediate: () => 0, clearImmediate: noop, - createHash: s => s + createHash: Harness.LanguageService.mockHash, }; const mockLogger: Logger = { diff --git a/src/harness/unittests/telemetry.ts b/src/harness/unittests/telemetry.ts index f250c732c0b..02be254c6f9 100644 --- a/src/harness/unittests/telemetry.ts +++ b/src/harness/unittests/telemetry.ts @@ -9,6 +9,7 @@ namespace ts.projectSystem { et.service.openClientFile(file.path); assert.equal(et.getEvents().length, 0); }); + it("only sends an event once", () => { const file = makeFile("/a.ts"); const tsconfig = makeFile("/tsconfig.json", {}); @@ -46,12 +47,13 @@ namespace ts.projectSystem { const et = new EventTracker([file1]); const compilerOptions: ts.CompilerOptions = { strict: true }; - const projectFileName = "foo.csproj"; + const projectFileName = "/hunter2/foo.csproj"; open(); // TODO: Apparently compilerOptions is mutated, so have to repeat it here! et.assertProjectInfoTelemetryEvent({ + projectId: Harness.LanguageService.mockHash("/hunter2/foo.csproj"), compilerOptions: { strict: true }, compileOnSave: true, // These properties can't be present for an external project, so they are undefined instead of false. @@ -195,6 +197,7 @@ namespace ts.projectSystem { const et = new EventTracker([jsconfig, file]); et.service.openClientFile(file.path); et.assertProjectInfoTelemetryEvent({ + projectId: Harness.LanguageService.mockHash("/jsconfig.json"), fileStats: fileStats({ js: 1 }), compilerOptions: autoJsCompilerOptions, typeAcquisition: { @@ -214,6 +217,7 @@ namespace ts.projectSystem { et.service.openClientFile(file.path); et.getEvent(server.ProjectLanguageServiceStateEvent, /*mayBeMore*/ true); et.assertProjectInfoTelemetryEvent({ + projectId: Harness.LanguageService.mockHash("/jsconfig.json"), fileStats: fileStats({ js: 1 }), compilerOptions: autoJsCompilerOptions, configFileName: "jsconfig.json", @@ -248,7 +252,26 @@ namespace ts.projectSystem { } assertProjectInfoTelemetryEvent(partial: Partial): void { - assert.deepEqual(this.getEvent(ts.server.ProjectInfoTelemetryEvent), makePayload(partial)); + assert.deepEqual(this.getEvent(ts.server.ProjectInfoTelemetryEvent), { + projectId: Harness.LanguageService.mockHash("/tsconfig.json"), + fileStats: fileStats({ ts: 1 }), + compilerOptions: {}, + extends: false, + files: false, + include: false, + exclude: false, + compileOnSave: false, + typeAcquisition: { + enable: false, + exclude: false, + include: false, + }, + configFileName: "tsconfig.json", + projectType: "configured", + languageServiceEnabled: true, + version: ts.version, + ...partial, + }); } getEvent(eventName: T["eventName"], mayBeMore = false): T["data"] { @@ -260,28 +283,6 @@ namespace ts.projectSystem { } } - function makePayload(partial: Partial): server.ProjectInfoTelemetryEventData { - return { - fileStats: fileStats({ ts: 1 }), - compilerOptions: {}, - extends: false, - files: false, - include: false, - exclude: false, - compileOnSave: false, - typeAcquisition: { - enable: false, - exclude: false, - include: false, - }, - configFileName: "tsconfig.json", - projectType: "configured", - languageServiceEnabled: true, - version: ts.version, - ...partial - }; - } - function makeFile(path: string, content: {} = ""): projectSystem.FileOrFolder { return { path, content: typeof content === "string" ? "" : JSON.stringify(content) }; } diff --git a/src/harness/unittests/transpile.ts b/src/harness/unittests/transpile.ts index 20552ab9c2e..e0c96797827 100644 --- a/src/harness/unittests/transpile.ts +++ b/src/harness/unittests/transpile.ts @@ -36,7 +36,7 @@ namespace ts { transpileOptions.reportDiagnostics = true; - justName = "transpile/" + name.replace(/[^a-z0-9\-. ]/ig, "") + (transpileOptions.compilerOptions.jsx ? ".tsx" : ".ts"); + justName = "transpile/" + name.replace(/[^a-z0-9\-. ]/ig, "") + (transpileOptions.compilerOptions.jsx ? Extension.Tsx : Extension.Ts); toBeCompiled = [{ unitName: transpileOptions.fileName, content: input @@ -88,7 +88,7 @@ namespace ts { } it("Correct output for " + justName, () => { - Harness.Baseline.runBaseline(justName.replace(/\.tsx?$/, ".js"), () => { + Harness.Baseline.runBaseline(justName.replace(/\.tsx?$/, ts.Extension.Js), () => { if (transpileResult.outputText) { return transpileResult.outputText; } diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 7a19aa9167f..7c4a3068226 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -472,7 +472,7 @@ namespace ts.projectSystem { } createHash(s: string): string { - return s; + return Harness.LanguageService.mockHash(s); } triggerDirectoryWatcherCallback(directoryName: string, fileName: string): void { diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 3aa813c0a8a..da81bba5d78 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -3483,7 +3483,7 @@ interface DragEvent extends MouseEvent { declare var DragEvent: { prototype: DragEvent; - new(): DragEvent; + new(type: "drag" | "dragend" | "dragenter" | "dragexit" | "dragleave" | "dragover" | "dragstart" | "drop", dragEventInit?: { dataTransfer?: DataTransfer }): DragEvent; }; interface DynamicsCompressorNode extends AudioNode { @@ -8224,6 +8224,7 @@ interface Navigator extends Object, NavigatorID, NavigatorOnLine, NavigatorConte readonly serviceWorker: ServiceWorkerContainer; readonly webdriver: boolean; readonly hardwareConcurrency: number; + readonly languages: string[]; getGamepads(): Gamepad[]; javaEnabled(): boolean; msLaunchUri(uri: string, successCallback?: MSLaunchUriCallback, noHandlerCallback?: MSLaunchUriCallback): void; diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 7c0e0a0fb92..dd58935119b 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -37,6 +37,8 @@ namespace ts.server { } export interface ProjectInfoTelemetryEventData { + /** Cryptographically secure hash of project file location. */ + readonly projectId: string; /** Count of file extensions seen in the project. */ readonly fileStats: FileStats; /** @@ -1049,6 +1051,7 @@ namespace ts.server { if (!this.eventHandler) return; const data: ProjectInfoTelemetryEventData = { + projectId: this.host.createHash(projectKey), fileStats: countEachFileTypes(project.getScriptInfos()), compilerOptions: convertCompilerOptionsForTelemetry(project.getCompilerOptions()), typeAcquisition: convertTypeAcquisition(project.getTypeAcquisition()), diff --git a/src/server/project.ts b/src/server/project.ts index be854f948ea..65933b2e1bd 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -25,7 +25,7 @@ namespace ts.server { result.jsx += 1; break; case ScriptKind.TS: - fileExtensionIs(info.fileName, ".d.ts") + fileExtensionIs(info.fileName, Extension.Dts) ? result.dts += 1 : result.ts += 1; break; diff --git a/src/server/server.ts b/src/server/server.ts index fa90e8df88d..5f2b7054755 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -35,6 +35,7 @@ namespace ts.server { } = require("os"); function getGlobalTypingsCacheLocation() { + const versionMajorMinor = ts.version.match(/\d+\.\d+/)[0]; switch (process.platform) { case "win32": { const basePath = process.env.LOCALAPPDATA || @@ -43,7 +44,7 @@ namespace ts.server { process.env.USERPROFILE || (process.env.HOMEDRIVE && process.env.HOMEPATH && normalizeSlashes(process.env.HOMEDRIVE + process.env.HOMEPATH)) || os.tmpdir(); - return combinePaths(normalizeSlashes(basePath), "Microsoft/TypeScript"); + return combinePaths(combinePaths(normalizeSlashes(basePath), "Microsoft/TypeScript"), versionMajorMinor); } case "openbsd": case "freebsd": @@ -51,7 +52,7 @@ namespace ts.server { case "linux": case "android": { const cacheLocation = getNonWindowsCacheLocation(process.platform === "darwin"); - return combinePaths(cacheLocation, "typescript"); + return combinePaths(combinePaths(cacheLocation, "typescript"), versionMajorMinor); } default: Debug.fail(`unsupported platform '${process.platform}'`); diff --git a/src/server/session.ts b/src/server/session.ts index 828bcdce1ac..c06e33eb979 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -112,7 +112,13 @@ namespace ts.server { return true; } - export import CommandNames = protocol.CommandTypes; + // CommandNames used to be exposed before TS 2.4 as a namespace + // In TS 2.4 we switched to an enum, keep this for backward compatibility + // The var assignment ensures that even though CommandTypes are a const enum + // we want to ensure the value is maintained in the out since the file is + // built using --preseveConstEnum. + export type CommandNames = protocol.CommandTypes; + export const CommandNames = (protocol).CommandTypes; export function formatMessage(msg: T, logger: server.Logger, byteLength: (s: string, encoding: string) => number, newLine: string): string { const verboseLogging = logger.hasLevel(LogLevel.verbose); @@ -1569,7 +1575,7 @@ namespace ts.server { else { const info = this.projectService.getScriptInfo(fileNameInProject); if (!info.isScriptOpen()) { - if (fileNameInProject.indexOf(".d.ts") > 0) { + if (fileNameInProject.indexOf(Extension.Dts) > 0) { veryLowPriorityFiles.push(fileNameInProject); } else { diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 38da43bdee8..37aa8df0ca1 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -146,7 +146,7 @@ namespace ts.BreakpointResolver { case SyntaxKind.ForOfStatement: // span in initializer - return spanInInitializerOfForLike(node); + return spanInInitializerOfForLike(node); case SyntaxKind.SwitchStatement: // span on switch(...) diff --git a/src/services/classifier.ts b/src/services/classifier.ts index ca8cf52a09b..ff33059630d 100644 --- a/src/services/classifier.ts +++ b/src/services/classifier.ts @@ -724,8 +724,8 @@ namespace ts { pushCommentRange(pos, tag.pos - pos); } - pushClassification(tag.atToken.pos, tag.atToken.end - tag.atToken.pos, ClassificationType.punctuation); - pushClassification(tag.tagName.pos, tag.tagName.end - tag.tagName.pos, ClassificationType.docCommentTagName); + pushClassification(tag.atToken.pos, tag.atToken.end - tag.atToken.pos, ClassificationType.punctuation); // "@" + pushClassification(tag.tagName.pos, tag.tagName.end - tag.tagName.pos, ClassificationType.docCommentTagName); // e.g. "param" pos = tag.tagName.end; @@ -814,7 +814,7 @@ namespace ts { * False will mean that node is not classified and traverse routine should recurse into node contents. */ function tryClassifyNode(node: Node): boolean { - if (isJSDocNode(node)) { + if (isJSDoc(node)) { return true; } diff --git a/src/services/completions.ts b/src/services/completions.ts index 99560ffb4d8..071496a4224 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -445,7 +445,7 @@ namespace ts.Completions { } start = timestamp(); - const previousToken = findPrecedingToken(position, sourceFile); + const previousToken = findPrecedingToken(position, sourceFile, /*startNode*/ undefined, /*includeJsDoc*/ true); log("getCompletionData: Get previous token 1: " + (timestamp() - start)); // The decision to provide completion depends on the contextToken, which is determined through the previousToken. @@ -456,7 +456,7 @@ namespace ts.Completions { // Skip this partial identifier and adjust the contextToken to the token that precedes it. if (contextToken && position <= contextToken.end && isWord(contextToken.kind)) { const start = timestamp(); - contextToken = findPrecedingToken(contextToken.getFullStart(), sourceFile); + contextToken = findPrecedingToken(contextToken.getFullStart(), sourceFile, /*startNode*/ undefined, /*includeJsDoc*/ true); log("getCompletionData: Get previous token 2: " + (timestamp() - start)); } @@ -844,7 +844,7 @@ namespace ts.Completions { * * @returns true if 'symbols' was successfully populated; false otherwise. */ - function tryGetObjectLikeCompletionSymbols(objectLikeContainer: ObjectLiteralExpression | BindingPattern): boolean { + function tryGetObjectLikeCompletionSymbols(objectLikeContainer: ObjectLiteralExpression | ObjectBindingPattern): boolean { // We're looking up possible property names from contextual/inferred/declared type. isMemberCompletion = true; @@ -860,41 +860,36 @@ namespace ts.Completions { typeMembers = typeChecker.getAllPossiblePropertiesOfType(typeForObject); existingMembers = (objectLikeContainer).properties; } - else if (objectLikeContainer.kind === SyntaxKind.ObjectBindingPattern) { + else { + Debug.assert(objectLikeContainer.kind === SyntaxKind.ObjectBindingPattern); // We are *only* completing on properties from the type being destructured. isNewIdentifierLocation = false; const rootDeclaration = getRootDeclaration(objectLikeContainer.parent); - if (isVariableLike(rootDeclaration)) { - // We don't want to complete using the type acquired by the shape - // of the binding pattern; we are only interested in types acquired - // through type declaration or inference. - // Also proceed if rootDeclaration is a parameter and if its containing function expression/arrow function is contextually typed - - // type of parameter will flow in from the contextual type of the function - let canGetType = !!(rootDeclaration.initializer || rootDeclaration.type); - if (!canGetType && rootDeclaration.kind === SyntaxKind.Parameter) { - if (isExpression(rootDeclaration.parent)) { - canGetType = !!typeChecker.getContextualType(rootDeclaration.parent); - } - else if (rootDeclaration.parent.kind === SyntaxKind.MethodDeclaration || rootDeclaration.parent.kind === SyntaxKind.SetAccessor) { - canGetType = isExpression(rootDeclaration.parent.parent) && !!typeChecker.getContextualType(rootDeclaration.parent.parent); - } + if (!isVariableLike(rootDeclaration)) throw Debug.fail("Root declaration is not variable-like."); + + // We don't want to complete using the type acquired by the shape + // of the binding pattern; we are only interested in types acquired + // through type declaration or inference. + // Also proceed if rootDeclaration is a parameter and if its containing function expression/arrow function is contextually typed - + // type of parameter will flow in from the contextual type of the function + let canGetType = rootDeclaration.initializer || rootDeclaration.type || rootDeclaration.parent.parent.kind === SyntaxKind.ForOfStatement; + if (!canGetType && rootDeclaration.kind === SyntaxKind.Parameter) { + if (isExpression(rootDeclaration.parent)) { + canGetType = !!typeChecker.getContextualType(rootDeclaration.parent); } - if (canGetType) { - const typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer); - if (!typeForObject) return false; - // In a binding pattern, get only known properties. Everywhere else we will get all possible properties. - typeMembers = typeChecker.getPropertiesOfType(typeForObject); - existingMembers = (objectLikeContainer).elements; + else if (rootDeclaration.parent.kind === SyntaxKind.MethodDeclaration || rootDeclaration.parent.kind === SyntaxKind.SetAccessor) { + canGetType = isExpression(rootDeclaration.parent.parent) && !!typeChecker.getContextualType(rootDeclaration.parent.parent); } } - else { - Debug.fail("Root declaration is not variable-like."); + if (canGetType) { + const typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer); + if (!typeForObject) return false; + // In a binding pattern, get only known properties. Everywhere else we will get all possible properties. + typeMembers = typeChecker.getPropertiesOfType(typeForObject); + existingMembers = (objectLikeContainer).elements; } } - else { - Debug.fail("Expected object literal or binding pattern, got " + objectLikeContainer.kind); - } if (typeMembers && typeMembers.length > 0) { // Add filtered items to the completion list @@ -1003,14 +998,14 @@ namespace ts.Completions { * Returns the immediate owning object literal or binding pattern of a context token, * on the condition that one exists and that the context implies completion should be given. */ - function tryGetObjectLikeCompletionContainer(contextToken: Node): ObjectLiteralExpression | BindingPattern { + function tryGetObjectLikeCompletionContainer(contextToken: Node): ObjectLiteralExpression | ObjectBindingPattern { if (contextToken) { switch (contextToken.kind) { case SyntaxKind.OpenBraceToken: // const x = { | case SyntaxKind.CommaToken: // const x = { a: 0, | const parent = contextToken.parent; - if (parent && (parent.kind === SyntaxKind.ObjectLiteralExpression || parent.kind === SyntaxKind.ObjectBindingPattern)) { - return parent; + if (isObjectLiteralExpression(parent) || isObjectBindingPattern(parent)) { + return parent; } break; } diff --git a/src/services/documentHighlights.ts b/src/services/documentHighlights.ts index 36b72ecfa78..7ea8c519646 100644 --- a/src/services/documentHighlights.ts +++ b/src/services/documentHighlights.ts @@ -1,17 +1,23 @@ /* @internal */ namespace ts.DocumentHighlights { - export function getDocumentHighlights(program: Program, cancellationToken: CancellationToken, sourceFile: SourceFile, position: number, sourceFilesToSearch: SourceFile[]): DocumentHighlights[] { + export function getDocumentHighlights(program: Program, cancellationToken: CancellationToken, sourceFile: SourceFile, position: number, sourceFilesToSearch: SourceFile[]): DocumentHighlights[] | undefined { const node = getTouchingWord(sourceFile, position, /*includeJsDocComment*/ true); - return node && (getSemanticDocumentHighlights(node, program, cancellationToken, sourceFilesToSearch) || getSyntacticDocumentHighlights(node, sourceFile)); + if (!node) return undefined; + + if (isJsxOpeningElement(node.parent) && node.parent.tagName === node || isJsxClosingElement(node.parent)) { + // For a JSX element, just highlight the matching tag, not all references. + const { openingElement, closingElement } = node.parent.parent; + const highlightSpans = [openingElement, closingElement].map(({ tagName }) => getHighlightSpanForNode(tagName, sourceFile)); + return [{ fileName: sourceFile.fileName, highlightSpans }]; + } + + return getSemanticDocumentHighlights(node, program, cancellationToken, sourceFilesToSearch) || getSyntacticDocumentHighlights(node, sourceFile); } function getHighlightSpanForNode(node: Node, sourceFile: SourceFile): HighlightSpan { - const start = node.getStart(sourceFile); - const end = node.getEnd(); - return { fileName: sourceFile.fileName, - textSpan: createTextSpanFromBounds(start, end), + textSpan: createTextSpanFromNode(node, sourceFile), kind: HighlightSpanKind.none }; } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 67a967ec8b9..42d06e35f10 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -678,9 +678,7 @@ namespace ts.FindAllReferences.Core { return parent ? scope.getSourceFile() : scope; } - function getPossibleSymbolReferencePositions(sourceFile: SourceFile, symbolName: string, container: Node = sourceFile, fullStart = false): number[] { - const start = fullStart ? container.getFullStart() : container.getStart(sourceFile); - const end = container.getEnd(); + function getPossibleSymbolReferencePositions(sourceFile: SourceFile, symbolName: string, container: Node = sourceFile): number[] { const positions: number[] = []; /// TODO: Cache symbol existence for files to save text search @@ -695,10 +693,10 @@ namespace ts.FindAllReferences.Core { const sourceLength = text.length; const symbolNameLength = symbolName.length; - let position = text.indexOf(symbolName, start); + let position = text.indexOf(symbolName, container.pos); while (position >= 0) { // If we are past the end, stop looking - if (position > end) break; + if (position > container.end) break; // We found a match. Make sure it's not part of a larger word (i.e. the char // before and after it have to be a non-identifier char). @@ -759,8 +757,7 @@ namespace ts.FindAllReferences.Core { } function addReferencesForKeywordInFile(sourceFile: SourceFile, kind: SyntaxKind, searchText: string, references: Push): void { - // Want fullStart so we can find the symbol in JSDoc comments - const possiblePositions = getPossibleSymbolReferencePositions(sourceFile, searchText, sourceFile, /*fullStart*/ true); + const possiblePositions = getPossibleSymbolReferencePositions(sourceFile, searchText, sourceFile); for (const position of possiblePositions) { const referenceLocation = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true); if (referenceLocation.kind === kind) { @@ -784,8 +781,7 @@ namespace ts.FindAllReferences.Core { return; } - const fullStart = state.options.findInComments || container.jsDoc !== undefined || forEach(search.symbol.declarations, d => d.kind === ts.SyntaxKind.JSDocTypedefTag); - for (const position of getPossibleSymbolReferencePositions(sourceFile, search.text, container, fullStart)) { + for (const position of getPossibleSymbolReferencePositions(sourceFile, search.text, container)) { getReferencesAtLocation(sourceFile, position, search, state); } } diff --git a/src/services/navigateTo.ts b/src/services/navigateTo.ts index d4adeaea974..304f64f3cdb 100644 --- a/src/services/navigateTo.ts +++ b/src/services/navigateTo.ts @@ -10,7 +10,7 @@ namespace ts.NavigateTo { for (const sourceFile of sourceFiles) { cancellationToken.throwIfCancellationRequested(); - if (excludeDtsFiles && fileExtensionIs(sourceFile.fileName, ".d.ts")) { + if (excludeDtsFiles && fileExtensionIs(sourceFile.fileName, Extension.Dts)) { continue; } diff --git a/src/services/services.ts b/src/services/services.ts index 22fa67dd1c5..2f835d7de64 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -37,7 +37,7 @@ namespace ts { let ruleProvider: formatting.RulesProvider; function createNode(kind: TKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject | IdentifierObject { - const node = kind >= SyntaxKind.FirstNode ? new NodeObject(kind, pos, end) : + const node = isNodeKind(kind) ? new NodeObject(kind, pos, end) : kind === SyntaxKind.Identifier ? new IdentifierObject(SyntaxKind.Identifier, pos, end) : new TokenObject(kind, pos, end); node.parent = parent; @@ -103,10 +103,10 @@ namespace ts { return sourceFile.text.substring(this.getStart(sourceFile), this.getEnd()); } - private addSyntheticNodes(nodes: Node[], pos: number, end: number, useJSDocScanner?: boolean): number { + private addSyntheticNodes(nodes: Node[], pos: number, end: number): number { scanner.setTextPos(pos); while (pos < end) { - const token = useJSDocScanner ? scanner.scanJSDocToken() : scanner.scan(); + const token = scanner.scan(); Debug.assert(token !== SyntaxKind.EndOfFileToken); // Else it would infinitely loop const textPos = scanner.getTextPos(); if (textPos <= end) { @@ -136,54 +136,50 @@ namespace ts { } private createChildren(sourceFile?: SourceFileLike) { - if (this.kind === SyntaxKind.JSDocComment || isJSDocTag(this)) { + if (!isNodeKind(this.kind)) { + this._children = emptyArray; + return; + } + + if (isJSDocCommentContainingNode(this)) { /** Don't add trivia for "tokens" since this is in a comment. */ const children: Node[] = []; this.forEachChild(child => { children.push(child); }); this._children = children; + return; } - else if (this.kind >= SyntaxKind.FirstNode) { - const children: Node[] = []; - scanner.setText((sourceFile || this.getSourceFile()).text); - let pos = this.pos; - const useJSDocScanner = isJSDocNode(this); - const processNode = (node: Node) => { - const isJSDocTagNode = isJSDocNode(node); - if (!isJSDocTagNode && pos < node.pos) { - pos = this.addSyntheticNodes(children, pos, node.pos, useJSDocScanner); - } - children.push(node); - if (!isJSDocTagNode) { - pos = node.end; - } - }; - const processNodes = (nodes: NodeArray) => { - if (pos < nodes.pos) { - pos = this.addSyntheticNodes(children, pos, nodes.pos, useJSDocScanner); - } - children.push(this.createSyntaxList(nodes)); - pos = nodes.end; - }; - // jsDocComments need to be the first children - if (this.jsDoc) { - for (const jsDocComment of this.jsDoc) { - processNode(jsDocComment); - } + + const children: Node[] = []; + scanner.setText((sourceFile || this.getSourceFile()).text); + let pos = this.pos; + const processNode = (node: Node) => { + pos = this.addSyntheticNodes(children, pos, node.pos); + children.push(node); + pos = node.end; + }; + const processNodes = (nodes: NodeArray) => { + if (pos < nodes.pos) { + pos = this.addSyntheticNodes(children, pos, nodes.pos); } - // For syntactic classifications, all trivia are classcified together, including jsdoc comments. - // For that to work, the jsdoc comments should still be the leading trivia of the first child. - // Restoring the scanner position ensures that. - pos = this.pos; - forEachChild(this, processNode, processNodes); - if (pos < this.end) { - this.addSyntheticNodes(children, pos, this.end); + children.push(this.createSyntaxList(nodes)); + pos = nodes.end; + }; + // jsDocComments need to be the first children + if (this.jsDoc) { + for (const jsDocComment of this.jsDoc) { + processNode(jsDocComment); } - scanner.setText(undefined); - this._children = children; } - else { - this._children = emptyArray; + // For syntactic classifications, all trivia are classcified together, including jsdoc comments. + // For that to work, the jsdoc comments should still be the leading trivia of the first child. + // Restoring the scanner position ensures that. + pos = this.pos; + forEachChild(this, processNode, processNodes); + if (pos < this.end) { + this.addSyntheticNodes(children, pos, this.end); } + scanner.setText(undefined); + this._children = children; } public getChildCount(sourceFile?: SourceFile): number { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index ab958099c11..c5483251c61 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -94,6 +94,10 @@ namespace ts { else if (isNamespaceReference(node)) { return SemanticMeaning.Namespace; } + else if (isTypeParameterDeclaration(node.parent)) { + Debug.assert(isJSDocTemplateTag(node.parent.parent)); // Else would be handled by isDeclarationName + return SemanticMeaning.Type; + } else { return SemanticMeaning.Value; } @@ -710,7 +714,7 @@ namespace ts { } } - export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node): Node { + export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, includeJsDoc?: boolean): Node { return find(startNode || sourceFile); function findRightmostToken(n: Node): Node { @@ -741,7 +745,7 @@ namespace ts { // NOTE: JsxText is a weird kind of node that can contain only whitespaces (since they are not counted as trivia). // if this is the case - then we should assume that token in question is located in previous child. if (position < child.end && (nodeHasTokens(child) || child.kind === SyntaxKind.JsxText)) { - const start = child.getStart(sourceFile); + const start = (includeJsDoc && child.jsDoc ? child.jsDoc[0] : child).getStart(sourceFile); const lookInPreviousChild = (start >= position) || // cursor in the leading trivia (child.kind === SyntaxKind.JsxText && start === child.end); // whitespace only JsxText @@ -758,7 +762,7 @@ namespace ts { } } - Debug.assert(startNode !== undefined || n.kind === SyntaxKind.SourceFile); + Debug.assert(startNode !== undefined || n.kind === SyntaxKind.SourceFile || isJSDocCommentContainingNode(n)); // Here we know that none of child token nodes embrace the position, // the only known case is when position is at the end of the file. diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt index 0e8605efafd..28fe7c738a6 100644 --- a/tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt @@ -1,11 +1,58 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(47,1): error TS2322: Type '(x: number) => number[]' is not assignable to type '(x: T) => T[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(50,1): error TS2322: Type '(x: number) => string[]' is not assignable to type '(x: T) => string[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(53,1): error TS2322: Type '(x: number) => void' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(56,1): error TS2322: Type '(x: string, y: number) => string' is not assignable to type '(x: T, y: U) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(59,1): error TS2322: Type '(x: (arg: string) => number) => string' is not assignable to type '(x: (arg: T) => U) => T'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'string' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(62,1): error TS2322: Type '(x: (arg: Base) => Derived) => Base' is not assignable to type '(x: (arg: T) => U) => T'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(65,1): error TS2322: Type '(x: (arg: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U) => (r: T) => U'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(68,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: T) => U) => (r: T) => U'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. 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 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(74,1): error TS2322: Type '(...x: Derived[]) => Derived' is not assignable to type '(...x: T[]) => T'. + Type 'Derived' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(77,1): error TS2322: Type '(x: { foo: string; }, y: { foo: string; bar: string; }) => Base' is not assignable to type '(x: T, y: T) => T'. 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'. + Type 'T' is not assignable to type '{ foo: string; bar: string; }'. + Type 'Base' is not assignable to type '{ foo: string; bar: string; }'. + Property 'bar' is missing in type 'Base'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(80,1): error TS2322: Type '(x: Base[], y: Derived2[]) => Derived[]' is not assignable to type '(x: Base[], y: T) => Derived[]'. + Types of parameters 'y' and 'y' are incompatible. + Type 'T' is not assignable to type 'Derived2[]'. + Type 'Base[]' is not assignable to type 'Derived2[]'. + Type 'Base' is not assignable to type 'Derived2'. + Property 'baz' is missing in type 'Base'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(83,1): error TS2322: Type '(x: Base[], y: Derived[]) => Derived[]' is not assignable to type '(x: Base[], y: T) => T'. + Type 'Derived[]' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(86,1): error TS2322: Type '(x: { a: string; b: number; }) => Object' is not assignable to type '(x: { a: T; b: T; }) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'string'. -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts (14 errors) ==== // these are all permitted with the current rules, since we do not do contextual signature instantiation class Base { foo: string; } @@ -53,51 +100,111 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme var b: (x: T) => T[]; a = b; // ok b = a; // ok + ~ +!!! error TS2322: Type '(x: number) => number[]' is not assignable to type '(x: T) => T[]'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'number'. var b2: (x: T) => string[]; a2 = b2; // ok b2 = a2; // ok + ~~ +!!! error TS2322: Type '(x: number) => string[]' is not assignable to type '(x: T) => string[]'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'number'. var b3: (x: T) => T; a3 = b3; // ok b3 = a3; // ok + ~~ +!!! error TS2322: Type '(x: number) => void' is not assignable to type '(x: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'number'. var b4: (x: T, y: U) => T; a4 = b4; // ok b4 = a4; // ok + ~~ +!!! error TS2322: Type '(x: string, y: number) => string' is not assignable to type '(x: T, y: U) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'string'. var b5: (x: (arg: T) => U) => T; a5 = b5; // ok b5 = a5; // ok + ~~ +!!! error TS2322: Type '(x: (arg: string) => number) => string' is not assignable to type '(x: (arg: T) => U) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'T'. var b6: (x: (arg: T) => U) => T; a6 = b6; // ok b6 = a6; // ok + ~~ +!!! error TS2322: Type '(x: (arg: Base) => Derived) => Base' is not assignable to type '(x: (arg: T) => U) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b7: (x: (arg: T) => U) => (r: T) => U; a7 = b7; // ok b7 = a7; // ok + ~~ +!!! error TS2322: Type '(x: (arg: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U) => (r: T) => U'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b8: (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; a8 = b8; // ok b8 = a8; // 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: T) => U) => (r: T) => U'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. 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'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b10: (...x: T[]) => T; a10 = b10; // ok b10 = a10; // ok + ~~~ +!!! error TS2322: Type '(...x: Derived[]) => Derived' is not assignable to type '(...x: T[]) => T'. +!!! error TS2322: Type 'Derived' is not assignable to type 'T'. var b11: (x: T, y: T) => T; a11 = b11; // ok b11 = a11; // ok + ~~~ +!!! error TS2322: Type '(x: { foo: string; }, y: { foo: string; bar: string; }) => Base' is not assignable to type '(x: T, y: T) => T'. +!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type '{ foo: string; bar: string; }'. +!!! error TS2322: Type 'Base' is not assignable to type '{ foo: string; bar: string; }'. +!!! error TS2322: Property 'bar' is missing in type 'Base'. var b12: >(x: Array, y: T) => Array; a12 = b12; // ok b12 = a12; // ok + ~~~ +!!! error TS2322: Type '(x: Base[], y: Derived2[]) => Derived[]' is not assignable to type '(x: Base[], y: T) => Derived[]'. +!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'Derived2[]'. +!!! error TS2322: Type 'Base[]' is not assignable to type 'Derived2[]'. +!!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. +!!! error TS2322: Property 'baz' is missing in type 'Base'. var b13: >(x: Array, y: T) => T; a13 = b13; // ok b13 = a13; // ok + ~~~ +!!! error TS2322: Type '(x: Base[], y: Derived[]) => Derived[]' is not assignable to type '(x: Base[], y: T) => T'. +!!! error TS2322: Type 'Derived[]' is not assignable to type 'T'. var b14: (x: { a: T; b: T }) => T; a14 = b14; // ok b14 = a14; // ok + ~~~ +!!! error TS2322: Type '(x: { a: string; b: number; }) => Object' is not assignable to type '(x: { a: T; b: T; }) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'string'. var b15: (x: T) => T[]; a15 = b15; // ok b15 = a15; // ok diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt index df391b27f98..39d3a2a3593 100644 --- a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt @@ -1,3 +1,10 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(45,9): error TS2322: Type '(x: number) => string[]' is not assignable to type '(x: T) => U[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(49,9): error TS2322: Type '(x: (arg: Base) => Derived) => (r: Base) => Derived2' is not assignable to type '(x: (arg: T) => U) => (r: T) => V'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. 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. Types of parameters 'arg2' and 'arg2' are incompatible. @@ -5,14 +12,49 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme 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. - 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 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(58,9): error TS2322: Type '(...x: Base[]) => Base' is not assignable to type '(...x: T[]) => T'. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(62,9): error TS2322: Type '(x: { foo: string; }, y: { foo: string; bar: string; }) => Base' is not assignable to type '(x: T, y: T) => T'. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(66,9): error TS2322: Type '(x: Base[], y: Derived2[]) => Derived[]' is not assignable to type '(x: Base[], y: Base[]) => T'. + Type 'Derived[]' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(69,9): error TS2322: Type '(x: { a: T; b: T; }) => T' is not assignable to type '(x: { a: string; b: number; }) => number'. + Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(70,9): error TS2322: Type '(x: { a: string; b: number; }) => number' is not assignable to type '(x: { a: T; b: T; }) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(73,9): error TS2322: Type '(x: { a: T; b: T; }) => number' is not assignable to type '(x: { a: string; b: number; }) => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'. + Types of property 'a' are incompatible. + Type 'string' is not assignable to type 'Base'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(74,9): error TS2322: Type '(x: { a: string; b: number; }) => number' is not assignable to type '(x: { a: T; b: T; }) => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'string'. + Type 'Base' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(89,9): error TS2322: Type '(x: T) => string[]' is not assignable to type '(x: T) => T[]'. + Type 'string[]' is not assignable to type 'T[]'. + Type 'string' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(90,9): error TS2322: Type '(x: T) => T[]' is not assignable to type '(x: T) => string[]'. + Type 'T[]' is not assignable to type 'string[]'. + Type 'T' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(95,9): error TS2322: Type '(x: T) => T[]' is not assignable to type '(x: T) => string[]'. + Type 'T[]' is not assignable to type 'string[]'. + Type 'T' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(96,9): error TS2322: Type '(x: T) => string[]' is not assignable to type '(x: T) => T[]'. + Type 'string[]' is not assignable to type 'T[]'. + Type 'string' is not assignable to type 'T'. -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts (2 errors) ==== +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts (15 errors) ==== // These are mostly permitted with the current loose rules. All ok unless otherwise noted. module Errors { @@ -58,10 +100,19 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme var b2: (x: T) => U[]; a2 = b2; b2 = a2; + ~~ +!!! error TS2322: Type '(x: number) => string[]' is not assignable to type '(x: T) => U[]'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'number'. var b7: (x: (arg: T) => U) => (r: T) => V; a7 = b7; b7 = a7; + ~~ +!!! error TS2322: Type '(x: (arg: Base) => Derived) => (r: Base) => Derived2' is not assignable to type '(x: (arg: T) => U) => (r: T) => V'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b8: (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; a8 = b8; // error, { foo: number } and Base are incompatible @@ -75,32 +126,62 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme 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: 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 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b10: (...x: T[]) => T; a10 = b10; b10 = a10; + ~~~ +!!! error TS2322: Type '(...x: Base[]) => Base' is not assignable to type '(...x: T[]) => T'. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b11: (x: T, y: T) => T; a11 = b11; b11 = a11; + ~~~ +!!! error TS2322: Type '(x: { foo: string; }, y: { foo: string; bar: string; }) => Base' is not assignable to type '(x: T, y: T) => T'. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b12: >(x: Array, y: Array) => T; a12 = b12; b12 = a12; + ~~~ +!!! error TS2322: Type '(x: Base[], y: Derived2[]) => Derived[]' is not assignable to type '(x: Base[], y: Base[]) => T'. +!!! error TS2322: Type 'Derived[]' is not assignable to type 'T'. var b15: (x: { a: T; b: T }) => T; a15 = b15; + ~~~ +!!! error TS2322: Type '(x: { a: T; b: T; }) => T' is not assignable to type '(x: { a: string; b: number; }) => number'. +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. b15 = a15; + ~~~ +!!! error TS2322: Type '(x: { a: string; b: number; }) => number' is not assignable to type '(x: { a: T; b: T; }) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'string'. var b15a: (x: { a: T; b: T }) => number; a15 = b15a; + ~~~ +!!! error TS2322: Type '(x: { a: T; b: T; }) => number' is not assignable to type '(x: { a: string; b: number; }) => number'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'Base'. b15a = a15; + ~~~~ +!!! error TS2322: Type '(x: { a: string; b: number; }) => number' is not assignable to type '(x: { a: T; b: T; }) => number'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'string'. +!!! error TS2322: Type 'Base' is not assignable to type 'string'. var b16: (x: (a: T) => T) => T[]; a16 = b16; @@ -116,12 +197,28 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme var a2: (x: T) => T[]; var b2: (x: T) => string[]; a2 = b2; + ~~ +!!! error TS2322: Type '(x: T) => string[]' is not assignable to type '(x: T) => T[]'. +!!! error TS2322: Type 'string[]' is not assignable to type 'T[]'. +!!! error TS2322: Type 'string' is not assignable to type 'T'. b2 = a2; + ~~ +!!! error TS2322: Type '(x: T) => T[]' is not assignable to type '(x: T) => string[]'. +!!! error TS2322: Type 'T[]' is not assignable to type 'string[]'. +!!! error TS2322: Type 'T' is not assignable to type 'string'. // target type has generic call signature var a3: (x: T) => string[]; var b3: (x: T) => T[]; a3 = b3; + ~~ +!!! error TS2322: Type '(x: T) => T[]' is not assignable to type '(x: T) => string[]'. +!!! error TS2322: Type 'T[]' is not assignable to type 'string[]'. +!!! error TS2322: Type 'T' is not assignable to type 'string'. b3 = a3; + ~~ +!!! error TS2322: Type '(x: T) => string[]' is not assignable to type '(x: T) => T[]'. +!!! error TS2322: Type 'string[]' is not assignable to type 'T[]'. +!!! error TS2322: Type 'string' is not assignable to type 'T'. } } \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures5.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures5.errors.txt new file mode 100644 index 00000000000..ba8f5304aa2 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures5.errors.txt @@ -0,0 +1,93 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5.ts(40,1): error TS2322: Type '(x: T) => void' is not assignable to type '(x: T) => T'. + Type 'void' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5.ts(55,1): error TS2322: Type '(x: { a: T; b: T; }) => T[]' is not assignable to type '(x: { a: U; b: V; }) => U[]'. + Type '(U | V)[]' is not assignable to type 'U[]'. + Type 'U | V' is not assignable to type 'U'. + Type 'V' is not assignable to type 'U'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5.ts(58,1): error TS2322: Type '(x: { a: T; b: T; }) => T[]' is not assignable to type '(x: { a: U; b: V; }) => U[]'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: U; b: V; }' is not assignable to type '{ a: Base; b: Base; }'. + Types of property 'a' are incompatible. + Type 'U' is not assignable to type 'Base'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures5.ts (3 errors) ==== + // checking assignment compat for function types. No errors in this file + + 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: T) => T[]; + var a2: (x: T) => string[]; + var a3: (x: T) => void; + var a4: (x: T, y: U) => string; + var a5: (x: (arg: T) => U) => T; + var a6: (x: (arg: T) => Derived) => T; + var a11: (x: { foo: T }, y: { foo: T; bar: T }) => Base; + var a15: (x: { a: T; b: T }) => T[]; + var a16: (x: { a: T; b: T }) => T[]; + var a17: { + (x: (a: T) => T): T[]; + (x: (a: T) => T): T[]; + }; + var a18: { + (x: { + (a: T): T; + (a: T): T; + }): any[]; + (x: { + (a: T): T; + (a: T): T; + }): 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 + ~~ +!!! error TS2322: Type '(x: T) => void' is not assignable to type '(x: T) => T'. +!!! error TS2322: Type 'void' is not assignable to type 'T'. + var b4: (x: T, y: U) => string; + 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 b11: (x: { foo: T }, y: { foo: U; bar: U }) => Base; + a11 = b11; // ok + b11 = a11; // ok + var b15: (x: { a: U; b: V; }) => U[]; + a15 = b15; // ok, T = U, T = V + b15 = a15; // ok + ~~~ +!!! error TS2322: Type '(x: { a: T; b: T; }) => T[]' is not assignable to type '(x: { a: U; b: V; }) => U[]'. +!!! error TS2322: Type '(U | V)[]' is not assignable to type 'U[]'. +!!! error TS2322: Type 'U | V' is not assignable to type 'U'. +!!! error TS2322: Type 'V' is not assignable to type 'U'. + var b16: (x: { a: T; b: T }) => T[]; + a15 = b16; // ok + b15 = a16; // ok + ~~~ +!!! error TS2322: Type '(x: { a: T; b: T; }) => T[]' is not assignable to type '(x: { a: U; b: V; }) => U[]'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: U; b: V; }' is not assignable to type '{ a: Base; b: Base; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'U' is not assignable to type 'Base'. + var b17: (x: (a: T) => T) => T[]; + a17 = b17; // ok + b17 = a17; // ok + var b18: (x: (a: T) => T) => any[]; + a18 = b18; // ok + b18 = a18; // ok + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures6.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures6.errors.txt new file mode 100644 index 00000000000..b8399a1855b --- /dev/null +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures6.errors.txt @@ -0,0 +1,61 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6.ts(30,1): error TS2322: Type '(x: T) => void' is not assignable to type '(x: T) => T'. + Type 'void' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6.ts(42,1): error TS2322: Type '(x: { a: T; b: T; }) => T[]' is not assignable to type '(x: { a: T; b: T; }) => T[]'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: Base; b: Base; }'. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'Base'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures6.ts (2 errors) ==== + // checking assignment compatibility relations for function types. All valid + + class Base { foo: string; } + class Derived extends Base { bar: string; } + class Derived2 extends Derived { baz: string; } + class OtherDerived extends Base { bing: string; } + + interface A { + a: (x: T) => T[]; + a2: (x: T) => string[]; + a3: (x: T) => void; + a4: (x: T, y: U) => string; + a5: (x: (arg: T) => U) => T; + a6: (x: (arg: T) => Derived) => T; + a11: (x: { foo: T }, y: { foo: T; bar: T }) => Base; + a15: (x: { a: T; b: T }) => T[]; + a16: (x: { a: T; b: T }) => T[]; + } + + var x: A; + + var b: (x: T) => T[]; + x.a = b; + b = x.a; + var b2: (x: T) => string[]; + x.a2 = b2; + b2 = x.a2; + var b3: (x: T) => T; + x.a3 = b3; + b3 = x.a3; + ~~ +!!! error TS2322: Type '(x: T) => void' is not assignable to type '(x: T) => T'. +!!! error TS2322: Type 'void' is not assignable to type 'T'. + var b4: (x: T, y: U) => string; + x.a4 = b4; + b4 = x.a4; + var b5: (x: (arg: T) => U) => T; + x.a5 = b5; + b5 = x.a5; + var b11: (x: { foo: T }, y: { foo: U; bar: U }) => Base; + x.a11 = b11; + b11 = x.a11; + var b16: (x: { a: T; b: T }) => T[]; + x.a16 = b16; + b16 = x.a16; + ~~~ +!!! error TS2322: Type '(x: { a: T; b: T; }) => T[]' is not assignable to type '(x: { a: T; b: T; }) => T[]'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: Base; b: Base; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'Base'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt index 995a9b67ccd..f9a5be732c9 100644 --- a/tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt @@ -1,11 +1,58 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(47,1): error TS2322: Type 'new (x: number) => number[]' is not assignable to type 'new (x: T) => T[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(50,1): error TS2322: Type 'new (x: number) => string[]' is not assignable to type 'new (x: T) => string[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(53,1): error TS2322: Type 'new (x: number) => void' is not assignable to type 'new (x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(56,1): error TS2322: Type 'new (x: string, y: number) => string' is not assignable to type 'new (x: T, y: U) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(59,1): error TS2322: Type 'new (x: (arg: string) => number) => string' is not assignable to type 'new (x: (arg: T) => U) => T'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'string' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(62,1): error TS2322: Type 'new (x: (arg: Base) => Derived) => Base' is not assignable to type 'new (x: (arg: T) => U) => T'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(65,1): error TS2322: Type 'new (x: (arg: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U) => (r: T) => U'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(68,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: T) => U) => (r: T) => U'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. 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 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(74,1): error TS2322: Type 'new (...x: Derived[]) => Derived' is not assignable to type 'new (...x: T[]) => T'. + Type 'Derived' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(77,1): error TS2322: Type 'new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base' is not assignable to type 'new (x: T, y: T) => T'. 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'. + Type 'T' is not assignable to type '{ foo: string; bar: string; }'. + Type 'Base' is not assignable to type '{ foo: string; bar: string; }'. + Property 'bar' is missing in type 'Base'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(80,1): error TS2322: Type 'new (x: Base[], y: Derived2[]) => Derived[]' is not assignable to type 'new (x: Base[], y: T) => Derived[]'. + Types of parameters 'y' and 'y' are incompatible. + Type 'T' is not assignable to type 'Derived2[]'. + Type 'Base[]' is not assignable to type 'Derived2[]'. + Type 'Base' is not assignable to type 'Derived2'. + Property 'baz' is missing in type 'Base'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(83,1): error TS2322: Type 'new (x: Base[], y: Derived[]) => Derived[]' is not assignable to type 'new (x: Base[], y: T) => T'. + Type 'Derived[]' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(86,1): error TS2322: Type 'new (x: { a: string; b: number; }) => Object' is not assignable to type 'new (x: { a: T; b: T; }) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'string'. -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts (14 errors) ==== // checking assignment compatibility relations for function types. All of these are valid. class Base { foo: string; } @@ -53,51 +100,111 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme var b: new (x: T) => T[]; a = b; // ok b = a; // ok + ~ +!!! error TS2322: Type 'new (x: number) => number[]' is not assignable to type 'new (x: T) => T[]'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'number'. var b2: new (x: T) => string[]; a2 = b2; // ok b2 = a2; // ok + ~~ +!!! error TS2322: Type 'new (x: number) => string[]' is not assignable to type 'new (x: T) => string[]'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'number'. var b3: new (x: T) => T; a3 = b3; // ok b3 = a3; // ok + ~~ +!!! error TS2322: Type 'new (x: number) => void' is not assignable to type 'new (x: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'number'. var b4: new (x: T, y: U) => T; a4 = b4; // ok b4 = a4; // ok + ~~ +!!! error TS2322: Type 'new (x: string, y: number) => string' is not assignable to type 'new (x: T, y: U) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'string'. var b5: new (x: (arg: T) => U) => T; a5 = b5; // ok b5 = a5; // ok + ~~ +!!! error TS2322: Type 'new (x: (arg: string) => number) => string' is not assignable to type 'new (x: (arg: T) => U) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'T'. var b6: new (x: (arg: T) => U) => T; a6 = b6; // ok b6 = a6; // ok + ~~ +!!! error TS2322: Type 'new (x: (arg: Base) => Derived) => Base' is not assignable to type 'new (x: (arg: T) => U) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b7: new (x: (arg: T) => U) => (r: T) => U; a7 = b7; // ok b7 = a7; // ok + ~~ +!!! error TS2322: Type 'new (x: (arg: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U) => (r: T) => U'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b8: new (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; a8 = b8; // ok b8 = a8; // 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: T) => U) => (r: T) => U'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. 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'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b10: new (...x: T[]) => T; a10 = b10; // ok b10 = a10; // ok + ~~~ +!!! error TS2322: Type 'new (...x: Derived[]) => Derived' is not assignable to type 'new (...x: T[]) => T'. +!!! error TS2322: Type 'Derived' is not assignable to type 'T'. var b11: new (x: T, y: T) => T; a11 = b11; // ok b11 = a11; // ok + ~~~ +!!! error TS2322: Type 'new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base' is not assignable to type 'new (x: T, y: T) => T'. +!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type '{ foo: string; bar: string; }'. +!!! error TS2322: Type 'Base' is not assignable to type '{ foo: string; bar: string; }'. +!!! error TS2322: Property 'bar' is missing in type 'Base'. var b12: new >(x: Array, y: T) => Array; a12 = b12; // ok b12 = a12; // ok + ~~~ +!!! error TS2322: Type 'new (x: Base[], y: Derived2[]) => Derived[]' is not assignable to type 'new (x: Base[], y: T) => Derived[]'. +!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'Derived2[]'. +!!! error TS2322: Type 'Base[]' is not assignable to type 'Derived2[]'. +!!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. +!!! error TS2322: Property 'baz' is missing in type 'Base'. var b13: new >(x: Array, y: T) => T; a13 = b13; // ok b13 = a13; // ok + ~~~ +!!! error TS2322: Type 'new (x: Base[], y: Derived[]) => Derived[]' is not assignable to type 'new (x: Base[], y: T) => T'. +!!! error TS2322: Type 'Derived[]' is not assignable to type 'T'. var b14: new (x: { a: T; b: T }) => T; a14 = b14; // ok b14 = a14; // ok + ~~~ +!!! error TS2322: Type 'new (x: { a: string; b: number; }) => Object' is not assignable to type 'new (x: { a: T; b: T; }) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'string'. var b15: new (x: T) => T[]; a15 = b15; // ok b15 = a15; // ok diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt index 6b2f4a0de17..8679b1d85f1 100644 --- a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt @@ -1,3 +1,10 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(45,9): error TS2322: Type 'new (x: number) => string[]' is not assignable to type 'new (x: T) => U[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(49,9): error TS2322: Type 'new (x: (arg: Base) => Derived) => (r: Base) => Derived2' is not assignable to type 'new (x: (arg: T) => U) => (r: T) => V'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. 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. Types of parameters 'arg2' and 'arg2' are incompatible. @@ -5,11 +12,34 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme 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. - 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 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(58,9): error TS2322: Type 'new (...x: Base[]) => Base' is not assignable to type 'new (...x: T[]) => T'. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(62,9): error TS2322: Type 'new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base' is not assignable to type 'new (x: T, y: T) => T'. + Type 'Base' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(66,9): error TS2322: Type 'new (x: Base[], y: Derived2[]) => Derived[]' is not assignable to type 'new (x: Base[], y: Base[]) => T'. + Type 'Derived[]' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(69,9): error TS2322: Type 'new (x: { a: T; b: T; }) => T' is not assignable to type 'new (x: { a: string; b: number; }) => number'. + Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(70,9): error TS2322: Type 'new (x: { a: string; b: number; }) => number' is not assignable to type 'new (x: { a: T; b: T; }) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(73,9): error TS2322: Type 'new (x: { a: T; b: T; }) => number' is not assignable to type 'new (x: { a: string; b: number; }) => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'. + Types of property 'a' are incompatible. + Type 'string' is not assignable to type 'Base'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(74,9): error TS2322: Type 'new (x: { a: string; b: number; }) => number' is not assignable to type 'new (x: { a: T; b: T; }) => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'string'. + Type 'Base' is not assignable to type 'string'. 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'. @@ -26,9 +56,21 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme Types of parameters 'x' and 'x' are incompatible. Type '(a: any) => any' is not assignable to type '{ new (a: T): T; new (a: T): T; }'. Type '(a: any) => any' provides no match for the signature 'new (a: T): T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(89,9): error TS2322: Type 'new (x: T) => string[]' is not assignable to type 'new (x: T) => T[]'. + Type 'string[]' is not assignable to type 'T[]'. + Type 'string' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(90,9): error TS2322: Type 'new (x: T) => T[]' is not assignable to type 'new (x: T) => string[]'. + Type 'T[]' is not assignable to type 'string[]'. + Type 'T' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(95,9): error TS2322: Type 'new (x: T) => T[]' is not assignable to type 'new (x: T) => string[]'. + Type 'T[]' is not assignable to type 'string[]'. + Type 'T' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(96,9): error TS2322: Type 'new (x: T) => string[]' is not assignable to type 'new (x: T) => T[]'. + Type 'string[]' is not assignable to type 'T[]'. + Type 'string' is not assignable to type 'T'. -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts (6 errors) ==== +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts (19 errors) ==== // checking assignment compatibility relations for function types. module Errors { @@ -74,10 +116,19 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme var b2: new (x: T) => U[]; a2 = b2; // ok b2 = a2; // ok + ~~ +!!! error TS2322: Type 'new (x: number) => string[]' is not assignable to type 'new (x: T) => U[]'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'number'. var b7: new (x: (arg: T) => U) => (r: T) => V; a7 = b7; // ok b7 = a7; // ok + ~~ +!!! error TS2322: Type 'new (x: (arg: Base) => Derived) => (r: Base) => Derived2' is not assignable to type 'new (x: (arg: T) => U) => (r: T) => V'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b8: new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; a8 = b8; // error, type mismatch @@ -91,32 +142,62 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme 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: 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 'x' and 'x' are incompatible. +!!! error TS2322: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b10: new (...x: T[]) => T; a10 = b10; // ok b10 = a10; // ok + ~~~ +!!! error TS2322: Type 'new (...x: Base[]) => Base' is not assignable to type 'new (...x: T[]) => T'. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b11: new (x: T, y: T) => T; a11 = b11; // ok b11 = a11; // ok + ~~~ +!!! error TS2322: Type 'new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base' is not assignable to type 'new (x: T, y: T) => T'. +!!! error TS2322: Type 'Base' is not assignable to type 'T'. var b12: new >(x: Array, y: Array) => T; a12 = b12; // ok b12 = a12; // ok + ~~~ +!!! error TS2322: Type 'new (x: Base[], y: Derived2[]) => Derived[]' is not assignable to type 'new (x: Base[], y: Base[]) => T'. +!!! error TS2322: Type 'Derived[]' is not assignable to type 'T'. var b15: new (x: { a: T; b: T }) => T; a15 = b15; // ok + ~~~ +!!! error TS2322: Type 'new (x: { a: T; b: T; }) => T' is not assignable to type 'new (x: { a: string; b: number; }) => number'. +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. b15 = a15; // ok + ~~~ +!!! error TS2322: Type 'new (x: { a: string; b: number; }) => number' is not assignable to type 'new (x: { a: T; b: T; }) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'string'. var b15a: new (x: { a: T; b: T }) => number; a15 = b15a; // ok + ~~~ +!!! error TS2322: Type 'new (x: { a: T; b: T; }) => number' is not assignable to type 'new (x: { a: string; b: number; }) => number'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'Base'. b15a = a15; // ok + ~~~~ +!!! error TS2322: Type 'new (x: { a: string; b: number; }) => number' is not assignable to type 'new (x: { a: T; b: T; }) => number'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: string; b: number; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'string'. +!!! error TS2322: Type 'Base' is not assignable to type 'string'. var b16: new (x: (a: T) => T) => T[]; a16 = b16; // error @@ -152,12 +233,28 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme var a2: new (x: T) => T[]; var b2: new (x: T) => string[]; a2 = b2; // ok + ~~ +!!! error TS2322: Type 'new (x: T) => string[]' is not assignable to type 'new (x: T) => T[]'. +!!! error TS2322: Type 'string[]' is not assignable to type 'T[]'. +!!! error TS2322: Type 'string' is not assignable to type 'T'. b2 = a2; // ok + ~~ +!!! error TS2322: Type 'new (x: T) => T[]' is not assignable to type 'new (x: T) => string[]'. +!!! error TS2322: Type 'T[]' is not assignable to type 'string[]'. +!!! error TS2322: Type 'T' is not assignable to type 'string'. // target type has generic call signature var a3: new (x: T) => string[]; var b3: new (x: T) => T[]; a3 = b3; // ok + ~~ +!!! error TS2322: Type 'new (x: T) => T[]' is not assignable to type 'new (x: T) => string[]'. +!!! error TS2322: Type 'T[]' is not assignable to type 'string[]'. +!!! error TS2322: Type 'T' is not assignable to type 'string'. b3 = a3; // ok + ~~ +!!! error TS2322: Type 'new (x: T) => string[]' is not assignable to type 'new (x: T) => T[]'. +!!! error TS2322: Type 'string[]' is not assignable to type 'T[]'. +!!! error TS2322: Type 'string' is not assignable to type 'T'. } } \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures5.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures5.errors.txt new file mode 100644 index 00000000000..23e0c682fdc --- /dev/null +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures5.errors.txt @@ -0,0 +1,93 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5.ts(40,1): error TS2322: Type 'new (x: T) => void' is not assignable to type 'new (x: T) => T'. + Type 'void' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5.ts(55,1): error TS2322: Type 'new (x: { a: T; b: T; }) => T[]' is not assignable to type 'new (x: { a: U; b: V; }) => U[]'. + Type '(U | V)[]' is not assignable to type 'U[]'. + Type 'U | V' is not assignable to type 'U'. + Type 'V' is not assignable to type 'U'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5.ts(58,1): error TS2322: Type 'new (x: { a: T; b: T; }) => T[]' is not assignable to type 'new (x: { a: U; b: V; }) => U[]'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: U; b: V; }' is not assignable to type '{ a: Base; b: Base; }'. + Types of property 'a' are incompatible. + Type 'U' is not assignable to type 'Base'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures5.ts (3 errors) ==== + // checking assignment compat for function types. All 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: T) => T[]; + var a2: new (x: T) => string[]; + var a3: new (x: T) => void; + var a4: new (x: T, y: U) => string; + var a5: new (x: new (arg: T) => U) => T; + var a6: new (x: new (arg: T) => Derived) => T; + var a11: new (x: { foo: T }, y: { foo: T; bar: T }) => Base; + var a15: new (x: { a: T; b: T }) => T[]; + var a16: new (x: { a: T; b: T }) => T[]; + var a17: { + new (x: new (a: T) => T): T[]; + new (x: new (a: T) => T): T[]; + }; + var a18: { + new (x: { + new (a: T): T; + new (a: T): T; + }): any[]; + new (x: { + new (a: T): T; + new (a: T): T; + }): 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 + ~~ +!!! error TS2322: Type 'new (x: T) => void' is not assignable to type 'new (x: T) => T'. +!!! error TS2322: Type 'void' is not assignable to type 'T'. + var b4: new (x: T, y: U) => string; + a4 = b4; // ok + b4 = a4; // ok + var b5: new (x: new (arg: T) => U) => T; + a5 = b5; // ok + b5 = a5; // ok + var b6: new (x: new (arg: T) => U) => T; + a6 = b6; // ok + b6 = a6; // ok + var b11: new (x: { foo: T }, y: { foo: U; bar: U }) => Base; + a11 = b11; // ok + b11 = a11; // ok + var b15: new (x: { a: U; b: V; }) => U[]; + a15 = b15; // ok + b15 = a15; // ok + ~~~ +!!! error TS2322: Type 'new (x: { a: T; b: T; }) => T[]' is not assignable to type 'new (x: { a: U; b: V; }) => U[]'. +!!! error TS2322: Type '(U | V)[]' is not assignable to type 'U[]'. +!!! error TS2322: Type 'U | V' is not assignable to type 'U'. +!!! error TS2322: Type 'V' is not assignable to type 'U'. + var b16: new (x: { a: T; b: T }) => T[]; + a15 = b16; // ok + b15 = a16; // ok + ~~~ +!!! error TS2322: Type 'new (x: { a: T; b: T; }) => T[]' is not assignable to type 'new (x: { a: U; b: V; }) => U[]'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: U; b: V; }' is not assignable to type '{ a: Base; b: Base; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'U' is not assignable to type 'Base'. + var b17: new (x: new (a: T) => T) => T[]; + a17 = b17; // ok + b17 = a17; // ok + var b18: new (x: new (a: T) => T) => any[]; + a18 = b18; // ok + b18 = a18; // ok + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures6.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures6.errors.txt new file mode 100644 index 00000000000..f89db500202 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures6.errors.txt @@ -0,0 +1,61 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6.ts(30,1): error TS2322: Type 'new (x: T) => void' is not assignable to type 'new (x: T) => T'. + Type 'void' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6.ts(42,1): error TS2322: Type 'new (x: { a: T; b: T; }) => T[]' is not assignable to type 'new (x: { a: T; b: T; }) => T[]'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: Base; b: Base; }'. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'Base'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures6.ts (2 errors) ==== + // checking assignment compatibility relations for function types. All valid. + + class Base { foo: string; } + class Derived extends Base { bar: string; } + class Derived2 extends Derived { baz: string; } + class OtherDerived extends Base { bing: string; } + + interface A { + a: new (x: T) => T[]; + a2: new (x: T) => string[]; + a3: new (x: T) => void; + a4: new (x: T, y: U) => string; + a5: new (x: (arg: T) => U) => T; + a6: new (x: (arg: T) => Derived) => T; + a11: new (x: { foo: T }, y: { foo: T; bar: T }) => Base; + a15: new (x: { a: T; b: T }) => T[]; + a16: new (x: { a: T; b: T }) => T[]; + } + + var x: A; + + var b: new (x: T) => T[]; + x.a = b; + b = x.a; + var b2: new (x: T) => string[]; + x.a2 = b2; + b2 = x.a2; + var b3: new (x: T) => T; + x.a3 = b3; + b3 = x.a3; + ~~ +!!! error TS2322: Type 'new (x: T) => void' is not assignable to type 'new (x: T) => T'. +!!! error TS2322: Type 'void' is not assignable to type 'T'. + var b4: new (x: T, y: U) => string; + x.a4 = b4; + b4 = x.a4; + var b5: new (x: (arg: T) => U) => T; + x.a5 = b5; + b5 = x.a5; + var b11: new (x: { foo: T }, y: { foo: U; bar: U }) => Base; + x.a11 = b11; + b11 = x.a11; + var b16: new (x: { a: T; b: T }) => T[]; + x.a16 = b16; + b16 = x.a16; + ~~~ +!!! error TS2322: Type 'new (x: { a: T; b: T; }) => T[]' is not assignable to type 'new (x: { a: T; b: T; }) => T[]'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type '{ a: T; b: T; }' is not assignable to type '{ a: Base; b: Base; }'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'Base'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithGenericCallSignatures2.errors.txt b/tests/baselines/reference/assignmentCompatWithGenericCallSignatures2.errors.txt new file mode 100644 index 00000000000..7e39c3305a3 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatWithGenericCallSignatures2.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignatures2.ts(16,1): error TS2322: Type 'A' is not assignable to type 'B'. + Types of parameters 'y' and 'y' are incompatible. + Type 'S' is not assignable to type 'S[]'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignatures2.ts (1 errors) ==== + // some complex cases of assignment compat of generic signatures. No contextual signature instantiation + + interface A { + (x: T, ...y: T[][]): void + } + + interface B { + (x: S, ...y: S[]): void + } + + var a: A; + var b: B; + + // Both ok + a = b; + b = a; + ~ +!!! error TS2322: Type 'A' is not assignable to type 'B'. +!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2322: Type 'S' is not assignable to type 'S[]'. + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithGenericCallSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithGenericCallSignatures4.errors.txt new file mode 100644 index 00000000000..a38822b8044 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatWithGenericCallSignatures4.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignatures4.ts(12,1): error TS2322: Type '>(z: T) => void' is not assignable to type '>>(z: T) => void'. + Types of parameters 'z' and 'z' are incompatible. + Type 'T' is not assignable to type 'I2'. + Type 'I2>' is not assignable to type 'I2'. + Type 'I2' is not assignable to type 'T'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignatures4.ts (1 errors) ==== + // some complex cases of assignment compat of generic signatures. + + interface I2 { + p: T + } + + var x: >(z: T) => void + var y: >>(z: T) => void + + // These both do not make sense as we would eventually be comparing I2 to I2>, and they are self referencing anyway + x = y + y = x + ~ +!!! error TS2322: Type '>(z: T) => void' is not assignable to type '>>(z: T) => void'. +!!! error TS2322: Types of parameters 'z' and 'z' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'I2'. +!!! error TS2322: Type 'I2>' is not assignable to type 'I2'. +!!! error TS2322: Type 'I2' is not assignable to type 'T'. + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.errors.txt b/tests/baselines/reference/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.errors.txt index a18da8fd8f7..dbad415c5f8 100644 --- a/tests/baselines/reference/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.errors.txt @@ -1,12 +1,74 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(14,13): error TS2322: Type '(x: T) => any' is not assignable to type '() => T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(23,13): error TS2322: Type '(x: T, y: T) => any' is not assignable to type '(x: T) => T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(63,9): error TS2322: Type '() => T' is not assignable to type '() => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(64,9): error TS2322: Type '(x?: T) => T' is not assignable to type '() => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(65,9): error TS2322: Type '(x: T) => T' is not assignable to type '() => T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(66,9): error TS2322: Type '(x: T, y?: T) => T' is not assignable to type '() => T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(67,9): error TS2322: Type '(x?: T, y?: T) => T' is not assignable to type '() => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(69,9): error TS2322: Type '() => T' is not assignable to type '(x?: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(70,9): error TS2322: Type '(x?: T) => T' is not assignable to type '(x?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(71,9): error TS2322: Type '(x: T) => T' is not assignable to type '(x?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(72,9): error TS2322: Type '(x: T, y?: T) => T' is not assignable to type '(x?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(73,9): error TS2322: Type '(x?: T, y?: T) => T' is not assignable to type '(x?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(75,9): error TS2322: Type '() => T' is not assignable to type '(x: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(76,9): error TS2322: Type '(x?: T) => T' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(77,9): error TS2322: Type '(x: T) => T' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(78,9): error TS2322: Type '(x: T, y?: T) => T' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(79,9): error TS2322: Type '(x?: T, y?: T) => T' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(81,9): error TS2322: Type '() => T' is not assignable to type '(x: T, y?: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(82,9): error TS2322: Type '(x?: T) => T' is not assignable to type '(x: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(83,9): error TS2322: Type '(x: T) => T' is not assignable to type '(x: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(84,9): error TS2322: Type '(x: T, y?: T) => T' is not assignable to type '(x: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(85,9): error TS2322: Type '(x?: T, y?: T) => T' is not assignable to type '(x: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(87,9): error TS2322: Type '() => T' is not assignable to type '(x?: T, y?: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(88,9): error TS2322: Type '(x?: T) => T' is not assignable to type '(x?: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(89,9): error TS2322: Type '(x: T) => T' is not assignable to type '(x?: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(90,9): error TS2322: Type '(x: T, y?: T) => T' is not assignable to type '(x?: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(91,9): error TS2322: Type '(x?: T, y?: T) => T' is not assignable to type '(x?: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(107,13): error TS2322: Type '(x: T) => any' is not assignable to type '() => T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(116,13): error TS2322: Type '(x: T, y: T) => any' is not assignable to type '(x: T) => T'. -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts (6 errors) ==== +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts (29 errors) ==== // call signatures in derived types must have the same or fewer optional parameters as the target for assignment module ClassTypeParam { @@ -74,7 +136,13 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme // all errors b.a = t.a; + ~~~ +!!! error TS2322: Type '() => T' is not assignable to type '() => T'. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a = t.a2; + ~~~ +!!! error TS2322: Type '(x?: T) => T' is not assignable to type '() => T'. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a = t.a3; ~~~ !!! error TS2322: Type '(x: T) => T' is not assignable to type '() => T'. @@ -82,30 +150,109 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme ~~~ !!! error TS2322: Type '(x: T, y?: T) => T' is not assignable to type '() => T'. b.a = t.a5; + ~~~ +!!! error TS2322: Type '(x?: T, y?: T) => T' is not assignable to type '() => T'. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a2 = t.a; + ~~~~ +!!! error TS2322: Type '() => T' is not assignable to type '(x?: T) => T'. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a2 = t.a2; + ~~~~ +!!! error TS2322: Type '(x?: T) => T' is not assignable to type '(x?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a2 = t.a3; + ~~~~ +!!! error TS2322: Type '(x: T) => T' is not assignable to type '(x?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a2 = t.a4; + ~~~~ +!!! error TS2322: Type '(x: T, y?: T) => T' is not assignable to type '(x?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a2 = t.a5; + ~~~~ +!!! error TS2322: Type '(x?: T, y?: T) => T' is not assignable to type '(x?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a3 = t.a; + ~~~~ +!!! error TS2322: Type '() => T' is not assignable to type '(x: T) => T'. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a3 = t.a2; + ~~~~ +!!! error TS2322: Type '(x?: T) => T' is not assignable to type '(x: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a3 = t.a3; + ~~~~ +!!! error TS2322: Type '(x: T) => T' is not assignable to type '(x: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a3 = t.a4; + ~~~~ +!!! error TS2322: Type '(x: T, y?: T) => T' is not assignable to type '(x: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a3 = t.a5; + ~~~~ +!!! error TS2322: Type '(x?: T, y?: T) => T' is not assignable to type '(x: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a4 = t.a; + ~~~~ +!!! error TS2322: Type '() => T' is not assignable to type '(x: T, y?: T) => T'. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a4 = t.a2; + ~~~~ +!!! error TS2322: Type '(x?: T) => T' is not assignable to type '(x: T, y?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a4 = t.a3; + ~~~~ +!!! error TS2322: Type '(x: T) => T' is not assignable to type '(x: T, y?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a4 = t.a4; + ~~~~ +!!! error TS2322: Type '(x: T, y?: T) => T' is not assignable to type '(x: T, y?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a4 = t.a5; + ~~~~ +!!! error TS2322: Type '(x?: T, y?: T) => T' is not assignable to type '(x: T, y?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a5 = t.a; + ~~~~ +!!! error TS2322: Type '() => T' is not assignable to type '(x?: T, y?: T) => T'. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a5 = t.a2; + ~~~~ +!!! error TS2322: Type '(x?: T) => T' is not assignable to type '(x?: T, y?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a5 = t.a3; + ~~~~ +!!! error TS2322: Type '(x: T) => T' is not assignable to type '(x?: T, y?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a5 = t.a4; + ~~~~ +!!! error TS2322: Type '(x: T, y?: T) => T' is not assignable to type '(x?: T, y?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. b.a5 = t.a5; + ~~~~ +!!! error TS2322: Type '(x?: T, y?: T) => T' is not assignable to type '(x?: T, y?: T) => T'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. } } diff --git a/tests/baselines/reference/assignmentStricterConstraints.errors.txt b/tests/baselines/reference/assignmentStricterConstraints.errors.txt new file mode 100644 index 00000000000..c83e2fa3440 --- /dev/null +++ b/tests/baselines/reference/assignmentStricterConstraints.errors.txt @@ -0,0 +1,19 @@ +tests/cases/compiler/assignmentStricterConstraints.ts(7,1): error TS2322: Type '(x: T, y: S) => void' is not assignable to type '(x: T, y: S) => void'. + Types of parameters 'y' and 'y' are incompatible. + Type 'S' is not assignable to type 'T'. + + +==== tests/cases/compiler/assignmentStricterConstraints.ts (1 errors) ==== + var f = function (x: T, y: S): void { + x = y + } + + var g = function (x: T, y: S): void { } + + g = f + ~ +!!! error TS2322: Type '(x: T, y: S) => void' is not assignable to type '(x: T, y: S) => void'. +!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2322: Type 'S' is not assignable to type 'T'. + g(1, "") + \ No newline at end of file diff --git a/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt b/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt index 42940c0e412..027551ae4b8 100644 --- a/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt +++ b/tests/baselines/reference/asyncFunctionDeclaration15_es5.errors.txt @@ -4,10 +4,10 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1 tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(9,23): error TS1055: Type 'PromiseLike' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,23): error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(10,23): error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. - Type 'Thenable' is not assignable to type 'PromiseLike'. + Type 'Thenable' is not assignable to type 'PromiseLike'. Types of property 'then' are incompatible. - Type '() => void' is not assignable to type '(onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => PromiseLike'. - Type 'void' is not assignable to type 'PromiseLike'. + Type '() => void' is not assignable to type '(onfulfilled?: (value: T) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => PromiseLike'. + Type 'void' is not assignable to type 'PromiseLike'. tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(17,16): error TS1058: The return type of an async function must either be a valid promise or must not contain a callable 'then' member. tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration15_es5.ts(23,25): error TS1320: Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member. @@ -35,10 +35,10 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1 !!! error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. ~~~~~~~~ !!! error TS1055: Type 'typeof Thenable' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value. -!!! error TS1055: Type 'Thenable' is not assignable to type 'PromiseLike'. +!!! error TS1055: Type 'Thenable' is not assignable to type 'PromiseLike'. !!! error TS1055: Types of property 'then' are incompatible. -!!! error TS1055: Type '() => void' is not assignable to type '(onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => PromiseLike'. -!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike'. +!!! error TS1055: Type '() => void' is not assignable to type '(onfulfilled?: (value: T) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => PromiseLike'. +!!! error TS1055: Type 'void' is not assignable to type 'PromiseLike'. async function fn7() { return; } // valid: Promise async function fn8() { return 1; } // valid: Promise async function fn9() { return null; } // valid: Promise diff --git a/tests/baselines/reference/callSignatureAssignabilityInInheritance.errors.txt b/tests/baselines/reference/callSignatureAssignabilityInInheritance.errors.txt index d6efdd66868..3d9ecd65e3d 100644 --- a/tests/baselines/reference/callSignatureAssignabilityInInheritance.errors.txt +++ b/tests/baselines/reference/callSignatureAssignabilityInInheritance.errors.txt @@ -2,9 +2,13 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign Types of property 'a' are incompatible. Type '(x: number) => string' is not assignable to type '(x: number) => number'. Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance.ts(63,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. + Types of property 'a2' are incompatible. + Type '(x: T) => string' is not assignable to type '(x: T) => T'. + Type 'string' is not assignable to type 'T'. -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance.ts (2 errors) ==== module CallSignature { interface Base { // T // M's @@ -73,6 +77,11 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign // S's interface I3 extends Base2 { + ~~ +!!! error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type '(x: T) => string' is not assignable to type '(x: T) => T'. +!!! error TS2430: Type 'string' is not assignable to type 'T'. // N's a2: (x: T) => string; // error because base returns non-void; } diff --git a/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt b/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt index f5e05567b25..5bf725b06e3 100644 --- a/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt +++ b/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt @@ -11,9 +11,31 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign 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(76,19): error TS2430: Interface 'I6' incorrectly extends interface 'A'. + Types of property 'a15' are incompatible. + Type '(x: { a: T; b: T; }) => T' is not assignable to type '(x: { a: string; b: number; }) => number'. + Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts(80,19): error TS2430: Interface 'I7' incorrectly extends interface 'A'. + Types of property 'a15' are incompatible. + Type '(x: { a: T; b: T; }) => number' is not assignable to type '(x: { a: string; b: number; }) => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'. + Types of property 'a' are incompatible. + Type 'string' is not assignable to type 'Base'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts(100,19): error TS2430: Interface 'I6' incorrectly extends interface 'B'. + Types of property 'a2' are incompatible. + Type '(x: T) => string[]' is not assignable to type '(x: T) => T[]'. + Type 'string[]' is not assignable to type 'T[]'. + Type 'string' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts(109,19): error TS2430: Interface 'I7' incorrectly extends interface 'C'. + Types of property 'a2' are incompatible. + Type '(x: T) => T[]' is not assignable to type '(x: T) => string[]'. + Type 'T[]' is not assignable to type 'string[]'. + Type 'T' is not assignable to type 'string'. -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts (2 errors) ==== +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts (6 errors) ==== // checking subtype relations for function types as it relates to contextual signature instantiation // error cases @@ -105,10 +127,24 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign } interface I6 extends A { + ~~ +!!! error TS2430: Interface 'I6' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a15' are incompatible. +!!! error TS2430: Type '(x: { a: T; b: T; }) => T' is not assignable to type '(x: { a: string; b: number; }) => number'. +!!! error TS2430: Type 'string | number' is not assignable to type 'number'. +!!! error TS2430: Type 'string' is not assignable to type 'number'. a15: (x: { a: T; b: T }) => T; // error, T is {} which isn't an acceptable return type } interface I7 extends A { + ~~ +!!! error TS2430: Interface 'I7' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a15' are incompatible. +!!! error TS2430: Type '(x: { a: T; b: T; }) => number' is not assignable to type '(x: { a: string; b: number; }) => number'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type 'string' is not assignable to type 'Base'. a15: (x: { a: T; b: T }) => number; // error, T defaults to Base, which is not compatible with number or string } @@ -129,6 +165,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign } interface I6 extends B { + ~~ +!!! error TS2430: Interface 'I6' incorrectly extends interface 'B'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type '(x: T) => string[]' is not assignable to type '(x: T) => T[]'. +!!! error TS2430: Type 'string[]' is not assignable to type 'T[]'. +!!! error TS2430: Type 'string' is not assignable to type 'T'. a2: (x: T) => string[]; // error } @@ -138,6 +180,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign } interface I7 extends C { + ~~ +!!! error TS2430: Interface 'I7' incorrectly extends interface 'C'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type '(x: T) => T[]' is not assignable to type '(x: T) => string[]'. +!!! error TS2430: Type 'T[]' is not assignable to type 'string[]'. +!!! error TS2430: Type 'T' is not assignable to type 'string'. a2: (x: T) => T[]; // error } } diff --git a/tests/baselines/reference/callSignatureAssignabilityInInheritance6.errors.txt b/tests/baselines/reference/callSignatureAssignabilityInInheritance6.errors.txt new file mode 100644 index 00000000000..602e40dfcfb --- /dev/null +++ b/tests/baselines/reference/callSignatureAssignabilityInInheritance6.errors.txt @@ -0,0 +1,142 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6.ts(24,11): error TS2430: Interface 'I' incorrectly extends interface 'A'. + Types of property 'a' are incompatible. + Type '(x: T) => T[]' is not assignable to type '(x: T) => T[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6.ts(28,11): error TS2430: Interface 'I2' incorrectly extends interface 'A'. + Types of property 'a2' are incompatible. + Type '(x: T) => string[]' is not assignable to type '(x: T) => string[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6.ts(32,11): error TS2430: Interface 'I3' incorrectly extends interface 'A'. + Types of property 'a3' are incompatible. + Type '(x: T) => T' is not assignable to type '(x: T) => void'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6.ts(36,11): error TS2430: Interface 'I4' incorrectly extends interface 'A'. + Types of property 'a4' are incompatible. + Type '(x: T, y: U) => string' is not assignable to type '(x: T, y: U) => string'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6.ts(40,11): error TS2430: Interface 'I5' incorrectly extends interface 'A'. + Types of property 'a5' are incompatible. + Type '(x: (arg: T) => U) => T' is not assignable to type '(x: (arg: T) => U) => T'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6.ts(44,11): error TS2430: Interface 'I7' incorrectly extends interface 'A'. + Types of property 'a11' are incompatible. + Type '(x: { foo: T; }, y: { foo: U; bar: U; }) => Base' is not assignable to type '(x: { foo: T; }, y: { foo: T; bar: T; }) => Base'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ foo: T; }' is not assignable to type '{ foo: T; }'. Two different types with this name exist, but they are unrelated. + Types of property 'foo' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6.ts(48,11): error TS2430: Interface 'I9' incorrectly extends interface 'A'. + Types of property 'a16' are incompatible. + Type '(x: { a: T; b: T; }) => T[]' is not assignable to type '(x: { a: T; b: T; }) => T[]'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: T; b: T; }'. Two different types with this name exist, but they are unrelated. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + Type 'Base' is not assignable to type 'T'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance6.ts (7 errors) ==== + // checking subtype relations for function types as it relates to contextual signature instantiation + // same as subtypingWithCallSignatures4 but using class type parameters instead of generic signatures + // all are errors + + class Base { foo: string; } + class Derived extends Base { bar: string; } + class Derived2 extends Derived { baz: string; } + class OtherDerived extends Base { bing: string; } + + interface A { // T + // M's + a: (x: T) => T[]; + a2: (x: T) => string[]; + a3: (x: T) => void; + a4: (x: T, y: U) => string; + a5: (x: (arg: T) => U) => T; + a6: (x: (arg: T) => Derived) => T; + a11: (x: { foo: T }, y: { foo: T; bar: T }) => Base; + a15: (x: { a: T; b: T }) => T[]; + a16: (x: { a: T; b: T }) => T[]; + } + + // S's + interface I extends A { + ~ +!!! error TS2430: Interface 'I' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type '(x: T) => T[]' is not assignable to type '(x: T) => T[]'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a: (x: T) => T[]; + } + + interface I2 extends A { + ~~ +!!! error TS2430: Interface 'I2' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type '(x: T) => string[]' is not assignable to type '(x: T) => string[]'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a2: (x: T) => string[]; + } + + interface I3 extends A { + ~~ +!!! error TS2430: Interface 'I3' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a3' are incompatible. +!!! error TS2430: Type '(x: T) => T' is not assignable to type '(x: T) => void'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a3: (x: T) => T; + } + + interface I4 extends A { + ~~ +!!! error TS2430: Interface 'I4' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type '(x: T, y: U) => string' is not assignable to type '(x: T, y: U) => string'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a4: (x: T, y: U) => string; + } + + interface I5 extends A { + ~~ +!!! error TS2430: Interface 'I5' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type '(x: (arg: T) => U) => T' is not assignable to type '(x: (arg: T) => U) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a5: (x: (arg: T) => U) => T; + } + + interface I7 extends A { + ~~ +!!! error TS2430: Interface 'I7' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a11' are incompatible. +!!! error TS2430: Type '(x: { foo: T; }, y: { foo: U; bar: U; }) => Base' is not assignable to type '(x: { foo: T; }, y: { foo: T; bar: T; }) => Base'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type '{ foo: T; }' is not assignable to type '{ foo: T; }'. Two different types with this name exist, but they are unrelated. +!!! error TS2430: Types of property 'foo' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a11: (x: { foo: T }, y: { foo: U; bar: U }) => Base; + } + + interface I9 extends A { + ~~ +!!! error TS2430: Interface 'I9' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a16' are incompatible. +!!! error TS2430: Type '(x: { a: T; b: T; }) => T[]' is not assignable to type '(x: { a: T; b: T; }) => T[]'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type '{ a: T; b: T; }' is not assignable to type '{ a: T; b: T; }'. Two different types with this name exist, but they are unrelated. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +!!! error TS2430: Type 'Base' is not assignable to type 'T'. + a16: (x: { a: T; b: T }) => T[]; + } \ No newline at end of file diff --git a/tests/baselines/reference/checkJsdocReturnTag2.errors.txt b/tests/baselines/reference/checkJsdocReturnTag2.errors.txt new file mode 100644 index 00000000000..23a450c83ca --- /dev/null +++ b/tests/baselines/reference/checkJsdocReturnTag2.errors.txt @@ -0,0 +1,25 @@ +tests/cases/conformance/jsdoc/returns.js(6,5): error TS2322: Type '5' is not assignable to type 'string'. +tests/cases/conformance/jsdoc/returns.js(13,5): error TS2322: Type 'true | 5' is not assignable to type 'string | number'. + Type 'true' is not assignable to type 'string | number'. + + +==== tests/cases/conformance/jsdoc/returns.js (2 errors) ==== + // @ts-check + /** + * @returns {string} This comment is not currently exposed + */ + function f() { + return 5; + ~~~~~~~~~ +!!! error TS2322: Type '5' is not assignable to type 'string'. + } + + /** + * @returns {string | number} This comment is not currently exposed + */ + function f1() { + return 5 || true; + ~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type 'true | 5' is not assignable to type 'string | number'. +!!! error TS2322: Type 'true' is not assignable to type 'string | number'. + } \ No newline at end of file diff --git a/tests/baselines/reference/checkJsdocTypeTag1.types b/tests/baselines/reference/checkJsdocTypeTag1.types index 9368640edcb..898cf58806a 100644 --- a/tests/baselines/reference/checkJsdocTypeTag1.types +++ b/tests/baselines/reference/checkJsdocTypeTag1.types @@ -61,10 +61,10 @@ x(1); /** @type {function (number)} */ const x1 = (a) => a + 1; >x1 : (arg0: number) => any ->(a) => a + 1 : (a: any) => any ->a : any ->a + 1 : any ->a : any +>(a) => a + 1 : (a: number) => number +>a : number +>a + 1 : number +>a : number >1 : 1 x1(0); @@ -75,10 +75,10 @@ x1(0); /** @type {function (number): number} */ const x2 = (a) => a + 1; >x2 : (arg0: number) => number ->(a) => a + 1 : (a: any) => any ->a : any ->a + 1 : any ->a : any +>(a) => a + 1 : (a: number) => number +>a : number +>a + 1 : number +>a : number >1 : 1 x2(0); diff --git a/tests/baselines/reference/checkJsdocTypeTag2.errors.txt b/tests/baselines/reference/checkJsdocTypeTag2.errors.txt index ca02c578a36..3590c10e278 100644 --- a/tests/baselines/reference/checkJsdocTypeTag2.errors.txt +++ b/tests/baselines/reference/checkJsdocTypeTag2.errors.txt @@ -1,9 +1,10 @@ tests/cases/conformance/jsdoc/0.js(3,5): error TS2322: Type 'true' is not assignable to type 'string'. tests/cases/conformance/jsdoc/0.js(6,5): error TS2322: Type '"hello"' is not assignable to type 'number'. tests/cases/conformance/jsdoc/0.js(10,4): error TS2345: Argument of type '"string"' is not assignable to parameter of type 'number'. -tests/cases/conformance/jsdoc/0.js(13,7): error TS2451: Cannot redeclare block-scoped variable 'x2'. tests/cases/conformance/jsdoc/0.js(17,1): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/conformance/jsdoc/0.js(20,7): error TS2451: Cannot redeclare block-scoped variable 'x2'. +tests/cases/conformance/jsdoc/0.js(20,21): error TS2339: Property 'concat' does not exist on type 'number'. +tests/cases/conformance/jsdoc/0.js(24,7): error TS2322: Type '(a: number) => number' is not assignable to type '(arg0: number) => string'. + Type 'number' is not assignable to type 'string'. ==== tests/cases/conformance/jsdoc/0.js (6 errors) ==== @@ -26,8 +27,6 @@ tests/cases/conformance/jsdoc/0.js(20,7): error TS2451: Cannot redeclare block-s /** @type {function (number): number} */ const x2 = (a) => a + 1; - ~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'x2'. /** @type {string} */ var a; @@ -36,7 +35,14 @@ tests/cases/conformance/jsdoc/0.js(20,7): error TS2451: Cannot redeclare block-s !!! error TS2322: Type 'number' is not assignable to type 'string'. /** @type {function (number): number} */ - const x2 = (a) => a.concat("hi"); + const x3 = (a) => a.concat("hi"); + ~~~~~~ +!!! error TS2339: Property 'concat' does not exist on type 'number'. + x3(0); + + /** @type {function (number): string} */ + const x4 = (a) => a + 1; ~~ -!!! error TS2451: Cannot redeclare block-scoped variable 'x2'. - x2(0); \ No newline at end of file +!!! error TS2322: Type '(a: number) => number' is not assignable to type '(arg0: number) => string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + x4(0); \ No newline at end of file diff --git a/tests/baselines/reference/checkJsdocTypeTag2.js b/tests/baselines/reference/checkJsdocTypeTag2.js index 23b436e2031..0e550d3ba33 100644 --- a/tests/baselines/reference/checkJsdocTypeTag2.js +++ b/tests/baselines/reference/checkJsdocTypeTag2.js @@ -18,8 +18,12 @@ var a; a = x2(0); /** @type {function (number): number} */ -const x2 = (a) => a.concat("hi"); -x2(0); +const x3 = (a) => a.concat("hi"); +x3(0); + +/** @type {function (number): string} */ +const x4 = (a) => a + 1; +x4(0); //// [0.js] // @ts-check @@ -36,5 +40,8 @@ var x2 = function (a) { return a + 1; }; var a; a = x2(0); /** @type {function (number): number} */ -var x2 = function (a) { return a.concat("hi"); }; -x2(0); +var x3 = function (a) { return a.concat("hi"); }; +x3(0); +/** @type {function (number): string} */ +var x4 = function (a) { return a + 1; }; +x4(0); diff --git a/tests/baselines/reference/constructSignatureAssignabilityInInheritance.errors.txt b/tests/baselines/reference/constructSignatureAssignabilityInInheritance.errors.txt index 51278fc3f44..cc2c1e871e5 100644 --- a/tests/baselines/reference/constructSignatureAssignabilityInInheritance.errors.txt +++ b/tests/baselines/reference/constructSignatureAssignabilityInInheritance.errors.txt @@ -2,9 +2,13 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/construc Types of property 'a' are incompatible. Type 'new (x: number) => string' is not assignable to type 'new (x: number) => number'. Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance.ts(67,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. + Types of property 'a2' are incompatible. + Type 'new (x: T) => string' is not assignable to type 'new (x: T) => T'. + Type 'string' is not assignable to type 'T'. -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance.ts (2 errors) ==== // Checking basic subtype relations with construct signatures module ConstructSignature { @@ -77,6 +81,11 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/construc // S's interface I3 extends Base2 { + ~~ +!!! error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type 'new (x: T) => string' is not assignable to type 'new (x: T) => T'. +!!! error TS2430: Type 'string' is not assignable to type 'T'. // N's a2: new (x: T) => string; // error because base returns non-void; } diff --git a/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt b/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt index 7bd76159391..9646acd071f 100644 --- a/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt +++ b/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt @@ -11,9 +11,31 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/construc 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(66,19): error TS2430: Interface 'I6' incorrectly extends interface 'A'. + Types of property 'a15' are incompatible. + Type 'new (x: { a: T; b: T; }) => T' is not assignable to type 'new (x: { a: string; b: number; }) => number'. + Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts(70,19): error TS2430: Interface 'I7' incorrectly extends interface 'A'. + Types of property 'a15' are incompatible. + Type 'new (x: { a: T; b: T; }) => number' is not assignable to type 'new (x: { a: string; b: number; }) => number'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'. + Types of property 'a' are incompatible. + Type 'string' is not assignable to type 'Base'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts(86,19): error TS2430: Interface 'I6' incorrectly extends interface 'B'. + Types of property 'a2' are incompatible. + Type 'new (x: T) => string[]' is not assignable to type 'new (x: T) => T[]'. + Type 'string[]' is not assignable to type 'T[]'. + Type 'string' is not assignable to type 'T'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts(95,19): error TS2430: Interface 'I7' incorrectly extends interface 'C'. + Types of property 'a2' are incompatible. + Type 'new (x: T) => T[]' is not assignable to type 'new (x: T) => string[]'. + Type 'T[]' is not assignable to type 'string[]'. + Type 'T' is not assignable to type 'string'. -==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts (2 errors) ==== +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts (6 errors) ==== // checking subtype relations for function types as it relates to contextual signature instantiation // error cases @@ -95,10 +117,24 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/construc } interface I6 extends A { + ~~ +!!! error TS2430: Interface 'I6' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a15' are incompatible. +!!! error TS2430: Type 'new (x: { a: T; b: T; }) => T' is not assignable to type 'new (x: { a: string; b: number; }) => number'. +!!! error TS2430: Type 'string | number' is not assignable to type 'number'. +!!! error TS2430: Type 'string' is not assignable to type 'number'. a15: new (x: { a: T; b: T }) => T; // error, T is {} which isn't an acceptable return type } interface I7 extends A { + ~~ +!!! error TS2430: Interface 'I7' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a15' are incompatible. +!!! error TS2430: Type 'new (x: { a: T; b: T; }) => number' is not assignable to type 'new (x: { a: string; b: number; }) => number'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type '{ a: string; b: number; }' is not assignable to type '{ a: Base; b: Base; }'. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type 'string' is not assignable to type 'Base'. a15: new (x: { a: T; b: T }) => number; // error, T defaults to Base, which is not compatible with number or string } @@ -115,6 +151,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/construc } interface I6 extends B { + ~~ +!!! error TS2430: Interface 'I6' incorrectly extends interface 'B'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type 'new (x: T) => string[]' is not assignable to type 'new (x: T) => T[]'. +!!! error TS2430: Type 'string[]' is not assignable to type 'T[]'. +!!! error TS2430: Type 'string' is not assignable to type 'T'. a2: new (x: T) => string[]; // error } @@ -124,6 +166,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/construc } interface I7 extends C { + ~~ +!!! error TS2430: Interface 'I7' incorrectly extends interface 'C'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type 'new (x: T) => T[]' is not assignable to type 'new (x: T) => string[]'. +!!! error TS2430: Type 'T[]' is not assignable to type 'string[]'. +!!! error TS2430: Type 'T' is not assignable to type 'string'. a2: new (x: T) => T[]; // error } diff --git a/tests/baselines/reference/constructSignatureAssignabilityInInheritance6.errors.txt b/tests/baselines/reference/constructSignatureAssignabilityInInheritance6.errors.txt new file mode 100644 index 00000000000..6245fead919 --- /dev/null +++ b/tests/baselines/reference/constructSignatureAssignabilityInInheritance6.errors.txt @@ -0,0 +1,142 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6.ts(24,11): error TS2430: Interface 'I' incorrectly extends interface 'A'. + Types of property 'a' are incompatible. + Type 'new (x: T) => T[]' is not assignable to type 'new (x: T) => T[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6.ts(28,11): error TS2430: Interface 'I2' incorrectly extends interface 'A'. + Types of property 'a2' are incompatible. + Type 'new (x: T) => string[]' is not assignable to type 'new (x: T) => string[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6.ts(32,11): error TS2430: Interface 'I3' incorrectly extends interface 'A'. + Types of property 'a3' are incompatible. + Type 'new (x: T) => T' is not assignable to type 'new (x: T) => void'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6.ts(36,11): error TS2430: Interface 'I4' incorrectly extends interface 'A'. + Types of property 'a4' are incompatible. + Type 'new (x: T, y: U) => string' is not assignable to type 'new (x: T, y: U) => string'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6.ts(40,11): error TS2430: Interface 'I5' incorrectly extends interface 'A'. + Types of property 'a5' are incompatible. + Type 'new (x: (arg: T) => U) => T' is not assignable to type 'new (x: (arg: T) => U) => T'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6.ts(44,11): error TS2430: Interface 'I7' incorrectly extends interface 'A'. + Types of property 'a11' are incompatible. + Type 'new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base' is not assignable to type 'new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ foo: T; }' is not assignable to type '{ foo: T; }'. Two different types with this name exist, but they are unrelated. + Types of property 'foo' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6.ts(48,11): error TS2430: Interface 'I9' incorrectly extends interface 'A'. + Types of property 'a16' are incompatible. + Type 'new (x: { a: T; b: T; }) => T[]' is not assignable to type 'new (x: { a: T; b: T; }) => T[]'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: T; b: T; }'. Two different types with this name exist, but they are unrelated. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + Type 'Base' is not assignable to type 'T'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance6.ts (7 errors) ==== + // checking subtype relations for function types as it relates to contextual signature instantiation + // same as subtypingWithConstructSignatures4 but using class type parameters instead of generic signatures + // all are errors + + class Base { foo: string; } + class Derived extends Base { bar: string; } + class Derived2 extends Derived { baz: string; } + class OtherDerived extends Base { bing: string; } + + interface A { // T + // M's + a: new (x: T) => T[]; + a2: new (x: T) => string[]; + a3: new (x: T) => void; + a4: new (x: T, y: U) => string; + a5: new (x: (arg: T) => U) => T; + a6: new (x: (arg: T) => Derived) => T; + a11: new (x: { foo: T }, y: { foo: T; bar: T }) => Base; + a15: new (x: { a: T; b: T }) => T[]; + a16: new (x: { a: T; b: T }) => T[]; + } + + // S's + interface I extends A { + ~ +!!! error TS2430: Interface 'I' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type 'new (x: T) => T[]' is not assignable to type 'new (x: T) => T[]'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a: new (x: T) => T[]; + } + + interface I2 extends A { + ~~ +!!! error TS2430: Interface 'I2' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type 'new (x: T) => string[]' is not assignable to type 'new (x: T) => string[]'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a2: new (x: T) => string[]; + } + + interface I3 extends A { + ~~ +!!! error TS2430: Interface 'I3' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a3' are incompatible. +!!! error TS2430: Type 'new (x: T) => T' is not assignable to type 'new (x: T) => void'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a3: new (x: T) => T; + } + + interface I4 extends A { + ~~ +!!! error TS2430: Interface 'I4' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type 'new (x: T, y: U) => string' is not assignable to type 'new (x: T, y: U) => string'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a4: new (x: T, y: U) => string; + } + + interface I5 extends A { + ~~ +!!! error TS2430: Interface 'I5' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type 'new (x: (arg: T) => U) => T' is not assignable to type 'new (x: (arg: T) => U) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a5: new (x: (arg: T) => U) => T; + } + + interface I7 extends A { + ~~ +!!! error TS2430: Interface 'I7' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a11' are incompatible. +!!! error TS2430: Type 'new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base' is not assignable to type 'new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type '{ foo: T; }' is not assignable to type '{ foo: T; }'. Two different types with this name exist, but they are unrelated. +!!! error TS2430: Types of property 'foo' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a11: new (x: { foo: T }, y: { foo: U; bar: U }) => Base; + } + + interface I9 extends A { + ~~ +!!! error TS2430: Interface 'I9' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a16' are incompatible. +!!! error TS2430: Type 'new (x: { a: T; b: T; }) => T[]' is not assignable to type 'new (x: { a: T; b: T; }) => T[]'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type '{ a: T; b: T; }' is not assignable to type '{ a: T; b: T; }'. Two different types with this name exist, but they are unrelated. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +!!! error TS2430: Type 'Base' is not assignable to type 'T'. + a16: new (x: { a: T; b: T }) => T[]; + } \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypeFromJSDoc.symbols b/tests/baselines/reference/contextualTypeFromJSDoc.symbols new file mode 100644 index 00000000000..5ebe1e01ca7 --- /dev/null +++ b/tests/baselines/reference/contextualTypeFromJSDoc.symbols @@ -0,0 +1,48 @@ +=== tests/cases/conformance/types/contextualTypes/jsdoc/index.js === +/** @type {Array<[string, {x?:number, y?:number}]>} */ +const arr = [ +>arr : Symbol(arr, Decl(index.js, 1, 5)) + + ['a', { x: 1 }], +>x : Symbol(x, Decl(index.js, 2, 11)) + + ['b', { y: 2 }] +>y : Symbol(y, Decl(index.js, 3, 11)) + +]; + +/** @return {Array<[string, {x?:number, y?:number}]>} */ +function f() { +>f : Symbol(f, Decl(index.js, 4, 2)) + + return [ + ['a', { x: 1 }], +>x : Symbol(x, Decl(index.js, 9, 15)) + + ['b', { y: 2 }] +>y : Symbol(y, Decl(index.js, 10, 15)) + + ]; +} + +class C { +>C : Symbol(C, Decl(index.js, 12, 1)) + + /** @param {Array<[string, {x?:number, y?:number}]>} value */ + set x(value) { } +>x : Symbol(C.x, Decl(index.js, 14, 9), Decl(index.js, 16, 20)) +>value : Symbol(value, Decl(index.js, 16, 10)) + + get x() { +>x : Symbol(C.x, Decl(index.js, 14, 9), Decl(index.js, 16, 20)) + + return [ + ['a', { x: 1 }], +>x : Symbol(x, Decl(index.js, 19, 19)) + + ['b', { y: 2 }] +>y : Symbol(y, Decl(index.js, 20, 19)) + + ]; + } +} diff --git a/tests/baselines/reference/contextualTypeFromJSDoc.types b/tests/baselines/reference/contextualTypeFromJSDoc.types new file mode 100644 index 00000000000..f1121935d38 --- /dev/null +++ b/tests/baselines/reference/contextualTypeFromJSDoc.types @@ -0,0 +1,77 @@ +=== tests/cases/conformance/types/contextualTypes/jsdoc/index.js === +/** @type {Array<[string, {x?:number, y?:number}]>} */ +const arr = [ +>arr : [string, { x?: number; y?: number; }][] +>[ ['a', { x: 1 }], ['b', { y: 2 }]] : ([string, { x: number; }] | [string, { y: number; }])[] + + ['a', { x: 1 }], +>['a', { x: 1 }] : [string, { x: number; }] +>'a' : "a" +>{ x: 1 } : { x: number; } +>x : number +>1 : 1 + + ['b', { y: 2 }] +>['b', { y: 2 }] : [string, { y: number; }] +>'b' : "b" +>{ y: 2 } : { y: number; } +>y : number +>2 : 2 + +]; + +/** @return {Array<[string, {x?:number, y?:number}]>} */ +function f() { +>f : () => [string, { x?: number; y?: number; }][] + + return [ +>[ ['a', { x: 1 }], ['b', { y: 2 }] ] : ([string, { x: number; }] | [string, { y: number; }])[] + + ['a', { x: 1 }], +>['a', { x: 1 }] : [string, { x: number; }] +>'a' : "a" +>{ x: 1 } : { x: number; } +>x : number +>1 : 1 + + ['b', { y: 2 }] +>['b', { y: 2 }] : [string, { y: number; }] +>'b' : "b" +>{ y: 2 } : { y: number; } +>y : number +>2 : 2 + + ]; +} + +class C { +>C : C + + /** @param {Array<[string, {x?:number, y?:number}]>} value */ + set x(value) { } +>x : [string, { x?: number; y?: number; }][] +>value : [string, { x?: number; y?: number; }][] + + get x() { +>x : [string, { x?: number; y?: number; }][] + + return [ +>[ ['a', { x: 1 }], ['b', { y: 2 }] ] : ([string, { x: number; }] | [string, { y: number; }])[] + + ['a', { x: 1 }], +>['a', { x: 1 }] : [string, { x: number; }] +>'a' : "a" +>{ x: 1 } : { x: number; } +>x : number +>1 : 1 + + ['b', { y: 2 }] +>['b', { y: 2 }] : [string, { y: number; }] +>'b' : "b" +>{ y: 2 } : { y: number; } +>y : number +>2 : 2 + + ]; + } +} diff --git a/tests/baselines/reference/contextualTypingWithGenericSignature.types b/tests/baselines/reference/contextualTypingWithGenericSignature.types index e662f2c4192..cb70022a20b 100644 --- a/tests/baselines/reference/contextualTypingWithGenericSignature.types +++ b/tests/baselines/reference/contextualTypingWithGenericSignature.types @@ -16,9 +16,9 @@ var f2: { }; f2 = (x, y) => { return x } ->f2 = (x, y) => { return x } : (x: T, y: U) => T +>f2 = (x, y) => { return x } : (x: T, y: U) => T >f2 : (x: T, y: U) => T ->(x, y) => { return x } : (x: T, y: U) => T +>(x, y) => { return x } : (x: T, y: U) => T >x : T >y : U >x : T diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt new file mode 100644 index 00000000000..422d7fc280c --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt @@ -0,0 +1,30 @@ +tests/cases/compiler/excessPropertyCheckWithSpread.ts(6,3): error TS2345: Argument of type '{ n: number; a: number; }' is not assignable to parameter of type '{ a: any; }'. + Object literal may only specify known properties, and 'n' does not exist in type '{ a: any; }'. +tests/cases/compiler/excessPropertyCheckWithSpread.ts(16,3): error TS2345: Argument of type '{ opt: string | number; a: number; }' is not assignable to parameter of type '{ a: any; }'. + Object literal may only specify known properties, and 'opt' does not exist in type '{ a: any; }'. + + +==== tests/cases/compiler/excessPropertyCheckWithSpread.ts (2 errors) ==== + declare function f({ a: number }): void + interface I { + readonly n: number; + } + declare let i: I; + f({ a: 1, ...i }); + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ n: number; a: number; }' is not assignable to parameter of type '{ a: any; }'. +!!! error TS2345: Object literal may only specify known properties, and 'n' does not exist in type '{ a: any; }'. + + interface R { + opt?: number + } + interface L { + opt: string + } + declare let l: L; + declare let r: R; + f({ a: 1, ...l, ...r }); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ opt: string | number; a: number; }' is not assignable to parameter of type '{ a: any; }'. +!!! error TS2345: Object literal may only specify known properties, and 'opt' does not exist in type '{ a: any; }'. + \ No newline at end of file diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.js b/tests/baselines/reference/excessPropertyCheckWithSpread.js new file mode 100644 index 00000000000..d8dac07a3fb --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.js @@ -0,0 +1,30 @@ +//// [excessPropertyCheckWithSpread.ts] +declare function f({ a: number }): void +interface I { + readonly n: number; +} +declare let i: I; +f({ a: 1, ...i }); + +interface R { + opt?: number +} +interface L { + opt: string +} +declare let l: L; +declare let r: R; +f({ a: 1, ...l, ...r }); + + +//// [excessPropertyCheckWithSpread.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +f(__assign({ a: 1 }, i)); +f(__assign({ a: 1 }, l, r)); diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols b/tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols index 86f91c82663..3d0c33ebfc0 100644 --- a/tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly1.symbols @@ -45,7 +45,5 @@ g("", x => null, x => x.toLowerCase()); >g : Symbol(g, Decl(fixingTypeParametersRepeatedly1.ts, 1, 39), Decl(fixingTypeParametersRepeatedly1.ts, 4, 63)) >x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 6, 5)) >x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 6, 16)) ->x.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) >x : Symbol(x, Decl(fixingTypeParametersRepeatedly1.ts, 6, 16)) ->toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly1.types b/tests/baselines/reference/fixingTypeParametersRepeatedly1.types index 41e705ba943..d7326a515f5 100644 --- a/tests/baselines/reference/fixingTypeParametersRepeatedly1.types +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly1.types @@ -48,16 +48,16 @@ declare function g(); >g : { (x: T, y: (p: T) => T, z: (p: T) => T): T; (): any; } g("", x => null, x => x.toLowerCase()); ->g("", x => null, x => x.toLowerCase()) : string +>g("", x => null, x => x.toLowerCase()) : any >g : { (x: T, y: (p: T) => T, z: (p: T) => T): T; (): any; } >"" : "" >x => null : (x: string) => any >x : string >null : null ->x => x.toLowerCase() : (x: string) => string ->x : string ->x.toLowerCase() : string ->x.toLowerCase : () => string ->x : string ->toLowerCase : () => string +>x => x.toLowerCase() : (x: any) => any +>x : any +>x.toLowerCase() : any +>x.toLowerCase : any +>x : any +>toLowerCase : any diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt b/tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt index e56b58a268d..900d605d5fc 100644 --- a/tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly2.errors.txt @@ -1,11 +1,9 @@ tests/cases/compiler/fixingTypeParametersRepeatedly2.ts(11,27): error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. Type 'Base' is not assignable to type 'Derived'. Property 'toBase' is missing in type 'Base'. -tests/cases/compiler/fixingTypeParametersRepeatedly2.ts(17,27): error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. - Type 'Base' is not assignable to type 'Derived'. -==== tests/cases/compiler/fixingTypeParametersRepeatedly2.ts (2 errors) ==== +==== tests/cases/compiler/fixingTypeParametersRepeatedly2.ts (1 errors) ==== interface Base { baseProp; } @@ -26,7 +24,4 @@ tests/cases/compiler/fixingTypeParametersRepeatedly2.ts(17,27): error TS2345: Ar // The same error should be observed in both cases. declare function bar(x: T, func: (p: T) => T): T; declare function bar(x: T, func: (p: T) => T): T; - var result = bar(derived, d => d.toBase()); - ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(d: Derived) => Base' is not assignable to parameter of type '(p: Derived) => Derived'. -!!! error TS2345: Type 'Base' is not assignable to type 'Derived'. \ No newline at end of file + var result = bar(derived, d => d.toBase()); \ No newline at end of file diff --git a/tests/baselines/reference/fixingTypeParametersRepeatedly3.types b/tests/baselines/reference/fixingTypeParametersRepeatedly3.types index 3bf926276d2..beb195df5ed 100644 --- a/tests/baselines/reference/fixingTypeParametersRepeatedly3.types +++ b/tests/baselines/reference/fixingTypeParametersRepeatedly3.types @@ -66,8 +66,8 @@ declare function bar(x: T, func: (p: T) => T): T; >T : T var result2 = bar(derived, d => d.toBase()); ->result2 : Derived ->bar(derived, d => d.toBase()) : Derived +>result2 : Base +>bar(derived, d => d.toBase()) : Base >bar : { (x: T, func: (p: T) => T): T; (x: T, func: (p: T) => T): T; } >derived : Derived >d => d.toBase() : (d: Derived) => Base diff --git a/tests/baselines/reference/functionTypeArgumentAssignmentCompat.errors.txt b/tests/baselines/reference/functionTypeArgumentAssignmentCompat.errors.txt index 366e1732b29..2fa3cafcb1a 100644 --- a/tests/baselines/reference/functionTypeArgumentAssignmentCompat.errors.txt +++ b/tests/baselines/reference/functionTypeArgumentAssignmentCompat.errors.txt @@ -1,7 +1,9 @@ +tests/cases/compiler/functionTypeArgumentAssignmentCompat.ts(9,1): error TS2322: Type '() => S[]' is not assignable to type '(x: T) => T'. + Type '{}[]' is not assignable to type 'T'. tests/cases/compiler/functionTypeArgumentAssignmentCompat.ts(12,1): error TS2304: Cannot find name 'console'. -==== tests/cases/compiler/functionTypeArgumentAssignmentCompat.ts (1 errors) ==== +==== tests/cases/compiler/functionTypeArgumentAssignmentCompat.ts (2 errors) ==== var f : { (x:T): T; } @@ -11,6 +13,9 @@ tests/cases/compiler/functionTypeArgumentAssignmentCompat.ts(12,1): error TS2304 } = () => []; f = g; + ~ +!!! error TS2322: Type '() => S[]' is not assignable to type '(x: T) => T'. +!!! error TS2322: Type '{}[]' is not assignable to type 'T'. var s = f("str").toUpperCase(); console.log(s); diff --git a/tests/baselines/reference/generatorTypeCheck63.errors.txt b/tests/baselines/reference/generatorTypeCheck63.errors.txt index ed2ed36a438..c08635e8b73 100644 --- a/tests/baselines/reference/generatorTypeCheck63.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck63.errors.txt @@ -1,11 +1,12 @@ -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,14): error TS2322: Type '(a: State | 1) => IterableIterator' is not assignable to type 'Strategy'. - Type 'IterableIterator' is not assignable to type 'IterableIterator'. - Type 'State | 1' is not assignable to type 'State'. - Type '1' is not assignable to type 'State'. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,61): error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: StrategicState) => IterableIterator'. + Type 'IterableIterator' is not assignable to type 'IterableIterator'. + Type 'State | 1' is not assignable to type 'StrategicState'. + Type '1' has no properties in common with type 'StrategicState'. tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(29,70): error TS7025: Generator implicitly has type 'IterableIterator' because it does not yield any values. Consider supplying a return type. tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(32,42): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. Type argument candidate 'State' is not a valid type argument because it is not a supertype of candidate '1'. -tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): error TS2322: Type '(a: State | 1) => IterableIterator' is not assignable to type 'Strategy'. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,62): error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: StrategicState) => IterableIterator'. + Type 'IterableIterator' is not assignable to type 'IterableIterator'. ==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts (4 errors) ==== @@ -33,11 +34,11 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): err } export const Nothing: Strategy = strategy("Nothing", function* (state: State) { - ~~~~~~~ -!!! error TS2322: Type '(a: State | 1) => IterableIterator' is not assignable to type 'Strategy'. -!!! error TS2322: Type 'IterableIterator' is not assignable to type 'IterableIterator'. -!!! error TS2322: Type 'State | 1' is not assignable to type 'State'. -!!! error TS2322: Type '1' is not assignable to type 'State'. + ~~~~~~~~ +!!! error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: StrategicState) => IterableIterator'. +!!! error TS2345: Type 'IterableIterator' is not assignable to type 'IterableIterator'. +!!! error TS2345: Type 'State | 1' is not assignable to type 'StrategicState'. +!!! error TS2345: Type '1' has no properties in common with type 'StrategicState'. yield 1; return state; }); @@ -55,8 +56,9 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): err }); export const Nothing3: Strategy = strategy("Nothing", function* (state: State) { - ~~~~~~~~ -!!! error TS2322: Type '(a: State | 1) => IterableIterator' is not assignable to type 'Strategy'. + ~~~~~~~~ +!!! error TS2345: Argument of type '(state: State) => IterableIterator' is not assignable to parameter of type '(a: StrategicState) => IterableIterator'. +!!! error TS2345: Type 'IterableIterator' is not assignable to type 'IterableIterator'. yield state; return 1; }); \ No newline at end of file diff --git a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.errors.txt b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.errors.txt new file mode 100644 index 00000000000..9e9a7e9505d --- /dev/null +++ b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.errors.txt @@ -0,0 +1,30 @@ +tests/cases/compiler/genericArgumentCallSigAssignmentCompat.ts(16,31): error TS2345: Argument of type '(value: T) => T' is not assignable to parameter of type 'Iterator'. + Type 'string | number | boolean' is not assignable to type 'boolean'. + Type 'string' is not assignable to type 'boolean'. + + +==== tests/cases/compiler/genericArgumentCallSigAssignmentCompat.ts (1 errors) ==== + module Underscore { + export interface Iterator { + (value: T, index: any, list: any): U; + } + + export interface Static { + all(list: T[], iterator?: Iterator, context?: any): boolean; + identity(value: T): T; + } + } + + declare var _: Underscore.Static; + + // No error, Call signatures of types '(value: T) => T' and 'Underscore.Iterator<{}, boolean>' are compatible when instantiated with any. + // Ideally, we would not have a generic signature here, because it should be instantiated with {} during inferential typing + _.all([true, 1, null, 'yes'], _.identity); + ~~~~~~~~~~ +!!! error TS2345: Argument of type '(value: T) => T' is not assignable to parameter of type 'Iterator'. +!!! error TS2345: Type 'string | number | boolean' is not assignable to type 'boolean'. +!!! error TS2345: Type 'string' is not assignable to type 'boolean'. + + // Ok, because fixing makes us infer boolean for T + _.all([true], _.identity); + \ No newline at end of file diff --git a/tests/baselines/reference/genericAssignmentCompatOfFunctionSignatures1.errors.txt b/tests/baselines/reference/genericAssignmentCompatOfFunctionSignatures1.errors.txt new file mode 100644 index 00000000000..b2c6aa42013 --- /dev/null +++ b/tests/baselines/reference/genericAssignmentCompatOfFunctionSignatures1.errors.txt @@ -0,0 +1,34 @@ +tests/cases/compiler/genericAssignmentCompatOfFunctionSignatures1.ts(4,1): error TS2322: Type '(x: T, z: U) => void' is not assignable to type '(x: T, z: U) => void'. + Types of parameters 'z' and 'z' are incompatible. + Type 'U' is not assignable to type '{ a: T; b: number; }'. + Type '{ a: T; b: string; }' is not assignable to type '{ a: T; b: number; }'. + Types of property 'b' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/genericAssignmentCompatOfFunctionSignatures1.ts(5,1): error TS2322: Type '(x: T, z: U) => void' is not assignable to type '(x: T, z: U) => void'. + Types of parameters 'z' and 'z' are incompatible. + Type 'U' is not assignable to type '{ a: T; b: string; }'. + Type '{ a: T; b: number; }' is not assignable to type '{ a: T; b: string; }'. + Types of property 'b' are incompatible. + Type 'number' is not assignable to type 'string'. + + +==== tests/cases/compiler/genericAssignmentCompatOfFunctionSignatures1.ts (2 errors) ==== + var x1 = function foo3(x: T, z: U) { } + var x2 = function foo3(x: T, z: U) { } + + x1 = x2; + ~~ +!!! error TS2322: Type '(x: T, z: U) => void' is not assignable to type '(x: T, z: U) => void'. +!!! error TS2322: Types of parameters 'z' and 'z' are incompatible. +!!! error TS2322: Type 'U' is not assignable to type '{ a: T; b: number; }'. +!!! error TS2322: Type '{ a: T; b: string; }' is not assignable to type '{ a: T; b: number; }'. +!!! error TS2322: Types of property 'b' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + x2 = x1; + ~~ +!!! error TS2322: Type '(x: T, z: U) => void' is not assignable to type '(x: T, z: U) => void'. +!!! error TS2322: Types of parameters 'z' and 'z' are incompatible. +!!! error TS2322: Type 'U' is not assignable to type '{ a: T; b: string; }'. +!!! error TS2322: Type '{ a: T; b: number; }' is not assignable to type '{ a: T; b: string; }'. +!!! error TS2322: Types of property 'b' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/genericContextualTypes1.types b/tests/baselines/reference/genericContextualTypes1.types index 4aedcd6e81b..b1a7aff8eef 100644 --- a/tests/baselines/reference/genericContextualTypes1.types +++ b/tests/baselines/reference/genericContextualTypes1.types @@ -125,7 +125,7 @@ const f01: (x: A) => A[] = x => [x]; >x : A >A : A >A : A ->x => [x] : (x: A) => A[] +>x => [x] : (x: A) => A[] >x : A >[x] : A[] >x : A @@ -356,7 +356,7 @@ type fn = (a: A) => A; const fn: fn = a => a; >fn : fn >fn : fn ->a => a : (a: A) => A +>a => a : (a: A) => A >a : A >a : A diff --git a/tests/baselines/reference/genericFunctionCallSignatureReturnTypeMismatch.errors.txt b/tests/baselines/reference/genericFunctionCallSignatureReturnTypeMismatch.errors.txt index a1051e0b020..a0c5cbb4378 100644 --- a/tests/baselines/reference/genericFunctionCallSignatureReturnTypeMismatch.errors.txt +++ b/tests/baselines/reference/genericFunctionCallSignatureReturnTypeMismatch.errors.txt @@ -1,13 +1,18 @@ +tests/cases/compiler/genericFunctionCallSignatureReturnTypeMismatch.ts(6,1): error TS2322: Type '() => S[]' is not assignable to type '(x: T) => T'. + Type '{}[]' is not assignable to type 'T'. tests/cases/compiler/genericFunctionCallSignatureReturnTypeMismatch.ts(10,1): error TS2304: Cannot find name 'console'. -==== tests/cases/compiler/genericFunctionCallSignatureReturnTypeMismatch.ts (1 errors) ==== +==== tests/cases/compiler/genericFunctionCallSignatureReturnTypeMismatch.ts (2 errors) ==== interface Array {} var f : { (x:T): T; } var g : { () : S[]; }; f = g; + ~ +!!! error TS2322: Type '() => S[]' is not assignable to type '(x: T) => T'. +!!! error TS2322: Type '{}[]' is not assignable to type 'T'. var s = f("str").toUpperCase(); diff --git a/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types b/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types index d6f64bdc933..2c1a8177e0b 100644 --- a/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types +++ b/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types @@ -9,11 +9,11 @@ function f(p: (x: T) => void) { }; f(x => f(y => x = y)); >f(x => f(y => x = y)) : void >f : (p: (x: T) => void) => void ->x => f(y => x = y) : (x: T) => void +>x => f(y => x = y) : (x: T) => void >x : T >f(y => x = y) : void >f : (p: (x: T) => void) => void ->y => x = y : (y: T) => T +>y => x = y : (y: T) => T >y : T >x = y : T >x : T diff --git a/tests/baselines/reference/genericImplements.errors.txt b/tests/baselines/reference/genericImplements.errors.txt new file mode 100644 index 00000000000..7add57989ce --- /dev/null +++ b/tests/baselines/reference/genericImplements.errors.txt @@ -0,0 +1,32 @@ +tests/cases/compiler/genericImplements.ts(8,7): error TS2420: Class 'X' incorrectly implements interface 'I'. + Types of property 'f' are incompatible. + Type '() => T' is not assignable to type '() => T'. + Type 'B' is not assignable to type 'T'. + + +==== tests/cases/compiler/genericImplements.ts (1 errors) ==== + class A { a; }; + class B { b; }; + interface I { + f(): T; + } // { f: () => { a; } } + + // OK + class X implements I { + ~ +!!! error TS2420: Class 'X' incorrectly implements interface 'I'. +!!! error TS2420: Types of property 'f' are incompatible. +!!! error TS2420: Type '() => T' is not assignable to type '() => T'. +!!! error TS2420: Type 'B' is not assignable to type 'T'. + f(): T { return undefined; } + } // { f: () => { b; } } + + // OK + class Y implements I { + f(): T { return undefined; } + } // { f: () => { a; } } + + // OK + class Z implements I { + f(): T { return undefined; } + } // { f: () => T } \ No newline at end of file diff --git a/tests/baselines/reference/genericSpecializations1.errors.txt b/tests/baselines/reference/genericSpecializations1.errors.txt new file mode 100644 index 00000000000..dd7e540661e --- /dev/null +++ b/tests/baselines/reference/genericSpecializations1.errors.txt @@ -0,0 +1,40 @@ +tests/cases/compiler/genericSpecializations1.ts(5,7): error TS2420: Class 'IntFooBad' incorrectly implements interface 'IFoo'. + Types of property 'foo' are incompatible. + Type '(x: string) => string' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'string'. +tests/cases/compiler/genericSpecializations1.ts(9,7): error TS2420: Class 'StringFoo2' incorrectly implements interface 'IFoo'. + Types of property 'foo' are incompatible. + Type '(x: string) => string' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'string'. + + +==== tests/cases/compiler/genericSpecializations1.ts (2 errors) ==== + interface IFoo { + foo(x: T): T; // no error on implementors because IFoo's T is different from foo's T + } + + class IntFooBad implements IFoo { + ~~~~~~~~~ +!!! error TS2420: Class 'IntFooBad' incorrectly implements interface 'IFoo'. +!!! error TS2420: Types of property 'foo' are incompatible. +!!! error TS2420: Type '(x: string) => string' is not assignable to type '(x: T) => T'. +!!! error TS2420: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2420: Type 'T' is not assignable to type 'string'. + foo(x: string): string { return null; } + } + + class StringFoo2 implements IFoo { + ~~~~~~~~~~ +!!! error TS2420: Class 'StringFoo2' incorrectly implements interface 'IFoo'. +!!! error TS2420: Types of property 'foo' are incompatible. +!!! error TS2420: Type '(x: string) => string' is not assignable to type '(x: T) => T'. +!!! error TS2420: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2420: Type 'T' is not assignable to type 'string'. + foo(x: string): string { return null; } + } + + class StringFoo3 implements IFoo { + foo(x: T): T { return null; } + } \ No newline at end of file diff --git a/tests/baselines/reference/genericSpecializations2.errors.txt b/tests/baselines/reference/genericSpecializations2.errors.txt index 9d58731b6fb..e570adb7912 100644 --- a/tests/baselines/reference/genericSpecializations2.errors.txt +++ b/tests/baselines/reference/genericSpecializations2.errors.txt @@ -1,8 +1,18 @@ +tests/cases/compiler/genericSpecializations2.ts(7,7): error TS2420: Class 'IntFooBad' incorrectly implements interface 'IFoo'. + Types of property 'foo' are incompatible. + Type '(x: string) => string' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'string'. tests/cases/compiler/genericSpecializations2.ts(8,9): error TS2368: Type parameter name cannot be 'string'. +tests/cases/compiler/genericSpecializations2.ts(11,7): error TS2420: Class 'StringFoo2' incorrectly implements interface 'IFoo'. + Types of property 'foo' are incompatible. + Type '(x: string) => string' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'string'. tests/cases/compiler/genericSpecializations2.ts(12,9): error TS2368: Type parameter name cannot be 'string'. -==== tests/cases/compiler/genericSpecializations2.ts (2 errors) ==== +==== tests/cases/compiler/genericSpecializations2.ts (4 errors) ==== class IFoo { foo(x: T): T { // no error on implementors because IFoo's T is different from foo's T return null; @@ -10,12 +20,24 @@ tests/cases/compiler/genericSpecializations2.ts(12,9): error TS2368: Type parame } class IntFooBad implements IFoo { + ~~~~~~~~~ +!!! error TS2420: Class 'IntFooBad' incorrectly implements interface 'IFoo'. +!!! error TS2420: Types of property 'foo' are incompatible. +!!! error TS2420: Type '(x: string) => string' is not assignable to type '(x: T) => T'. +!!! error TS2420: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2420: Type 'T' is not assignable to type 'string'. foo(x: string): string { return null; } ~~~~~~ !!! error TS2368: Type parameter name cannot be 'string'. } class StringFoo2 implements IFoo { + ~~~~~~~~~~ +!!! error TS2420: Class 'StringFoo2' incorrectly implements interface 'IFoo'. +!!! error TS2420: Types of property 'foo' are incompatible. +!!! error TS2420: Type '(x: string) => string' is not assignable to type '(x: T) => T'. +!!! error TS2420: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2420: Type 'T' is not assignable to type 'string'. foo(x: string): string { return null; } ~~~~~~ !!! error TS2368: Type parameter name cannot be 'string'. diff --git a/tests/baselines/reference/genericTypeArgumentInference1.errors.txt b/tests/baselines/reference/genericTypeArgumentInference1.errors.txt new file mode 100644 index 00000000000..7054967a475 --- /dev/null +++ b/tests/baselines/reference/genericTypeArgumentInference1.errors.txt @@ -0,0 +1,26 @@ +tests/cases/compiler/genericTypeArgumentInference1.ts(12,39): error TS2345: Argument of type '(value: T) => T' is not assignable to parameter of type 'Iterator'. + Type 'string | number | boolean' is not assignable to type 'boolean'. + Type 'string' is not assignable to type 'boolean'. + + +==== tests/cases/compiler/genericTypeArgumentInference1.ts (1 errors) ==== + module Underscore { + export interface Iterator { + (value: T, index: any, list: any): U; + } + export interface Static { + all(list: T[], iterator?: Iterator, context?: any): T; + identity(value: T): T; + } + } + declare var _: Underscore.Static; + + var r = _.all([true, 1, null, 'yes'], _.identity); + ~~~~~~~~~~ +!!! error TS2345: Argument of type '(value: T) => T' is not assignable to parameter of type 'Iterator'. +!!! error TS2345: Type 'string | number | boolean' is not assignable to type 'boolean'. +!!! error TS2345: Type 'string' is not assignable to type 'boolean'. + var r2 = _.all([true], _.identity); + var r3 = _.all([], _.identity); + var r4 = _.all([true], _.identity); + \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAssertions3.types b/tests/baselines/reference/genericTypeAssertions3.types index e46dd4aaa4e..2c1eb6b793b 100644 --- a/tests/baselines/reference/genericTypeAssertions3.types +++ b/tests/baselines/reference/genericTypeAssertions3.types @@ -6,8 +6,8 @@ var r = < (x: T) => T > ((x) => { return null; }); // bug was 'could not find >x : T >T : T >T : T ->((x) => { return null; }) : (x: T) => any ->(x) => { return null; } : (x: T) => any +>((x) => { return null; }) : (x: T) => any +>(x) => { return null; } : (x: T) => any >x : T >null : null diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.types b/tests/baselines/reference/implicitAnyGenericTypeInference.types index 4124c729f14..6ec751130d8 100644 --- a/tests/baselines/reference/implicitAnyGenericTypeInference.types +++ b/tests/baselines/reference/implicitAnyGenericTypeInference.types @@ -18,11 +18,11 @@ var c: Comparer; >Comparer : Comparer c = { compareTo: (x, y) => { return y; } }; ->c = { compareTo: (x, y) => { return y; } } : { compareTo: (x: any, y: U) => U; } +>c = { compareTo: (x, y) => { return y; } } : { compareTo: (x: any, y: U) => U; } >c : Comparer ->{ compareTo: (x, y) => { return y; } } : { compareTo: (x: any, y: U) => U; } ->compareTo : (x: any, y: U) => U ->(x, y) => { return y; } : (x: any, y: U) => U +>{ compareTo: (x, y) => { return y; } } : { compareTo: (x: any, y: U) => U; } +>compareTo : (x: any, y: U) => U +>(x, y) => { return y; } : (x: any, y: U) => U >x : any >y : U >y : U diff --git a/tests/baselines/reference/incrementOnNullAssertion.js b/tests/baselines/reference/incrementOnNullAssertion.js new file mode 100644 index 00000000000..1f56fa00f56 --- /dev/null +++ b/tests/baselines/reference/incrementOnNullAssertion.js @@ -0,0 +1,28 @@ +//// [incrementOnNullAssertion.ts] +interface Dictionary { + [myFavouriteType: string]: T | undefined +} +const x = 'bar' +let foo: Dictionary = {} +if (foo[x] === undefined) { + foo[x] = 1 +} +else { + let nu = foo[x] + let n = foo[x] + foo[x]!++ +} + + +//// [incrementOnNullAssertion.js] +"use strict"; +var x = 'bar'; +var foo = {}; +if (foo[x] === undefined) { + foo[x] = 1; +} +else { + var nu = foo[x]; + var n = foo[x]; + foo[x]++; +} diff --git a/tests/baselines/reference/incrementOnNullAssertion.symbols b/tests/baselines/reference/incrementOnNullAssertion.symbols new file mode 100644 index 00000000000..07f37e4aaa7 --- /dev/null +++ b/tests/baselines/reference/incrementOnNullAssertion.symbols @@ -0,0 +1,41 @@ +=== tests/cases/compiler/incrementOnNullAssertion.ts === +interface Dictionary { +>Dictionary : Symbol(Dictionary, Decl(incrementOnNullAssertion.ts, 0, 0)) +>T : Symbol(T, Decl(incrementOnNullAssertion.ts, 0, 21)) + + [myFavouriteType: string]: T | undefined +>myFavouriteType : Symbol(myFavouriteType, Decl(incrementOnNullAssertion.ts, 1, 5)) +>T : Symbol(T, Decl(incrementOnNullAssertion.ts, 0, 21)) +} +const x = 'bar' +>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5)) + +let foo: Dictionary = {} +>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3)) +>Dictionary : Symbol(Dictionary, Decl(incrementOnNullAssertion.ts, 0, 0)) + +if (foo[x] === undefined) { +>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3)) +>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5)) +>undefined : Symbol(undefined) + + foo[x] = 1 +>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3)) +>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5)) +} +else { + let nu = foo[x] +>nu : Symbol(nu, Decl(incrementOnNullAssertion.ts, 9, 7)) +>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3)) +>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5)) + + let n = foo[x] +>n : Symbol(n, Decl(incrementOnNullAssertion.ts, 10, 7)) +>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3)) +>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5)) + + foo[x]!++ +>foo : Symbol(foo, Decl(incrementOnNullAssertion.ts, 4, 3)) +>x : Symbol(x, Decl(incrementOnNullAssertion.ts, 3, 5)) +} + diff --git a/tests/baselines/reference/incrementOnNullAssertion.types b/tests/baselines/reference/incrementOnNullAssertion.types new file mode 100644 index 00000000000..f6acdda65bc --- /dev/null +++ b/tests/baselines/reference/incrementOnNullAssertion.types @@ -0,0 +1,53 @@ +=== tests/cases/compiler/incrementOnNullAssertion.ts === +interface Dictionary { +>Dictionary : Dictionary +>T : T + + [myFavouriteType: string]: T | undefined +>myFavouriteType : string +>T : T +} +const x = 'bar' +>x : "bar" +>'bar' : "bar" + +let foo: Dictionary = {} +>foo : Dictionary +>Dictionary : Dictionary +>{} : {} + +if (foo[x] === undefined) { +>foo[x] === undefined : boolean +>foo[x] : number | undefined +>foo : Dictionary +>x : "bar" +>undefined : undefined + + foo[x] = 1 +>foo[x] = 1 : 1 +>foo[x] : number | undefined +>foo : Dictionary +>x : "bar" +>1 : 1 +} +else { + let nu = foo[x] +>nu : number | undefined +>foo[x] : number | undefined +>foo : Dictionary +>x : "bar" + + let n = foo[x] +>n : number | undefined +>foo[x] : number | undefined +>foo : Dictionary +>x : "bar" + + foo[x]!++ +>foo[x]!++ : number +>foo[x]! : number +>foo[x] : number | undefined +>foo : Dictionary +>x : "bar" +} + diff --git a/tests/baselines/reference/isolatedModulesReExportType.errors.txt b/tests/baselines/reference/isolatedModulesReExportType.errors.txt index 10c07cde084..dc035a84c2f 100644 --- a/tests/baselines/reference/isolatedModulesReExportType.errors.txt +++ b/tests/baselines/reference/isolatedModulesReExportType.errors.txt @@ -35,4 +35,14 @@ declare type T = number; export = T; +==== /node_modules/foo/bar.d.ts (0 errors) ==== + export type T = number; + +==== /node_modules/foo/index.d.ts (0 errors) ==== + export { T } from "./bar"; // In a declaration file, so not an error. + +==== /node_modules/baz/index.d.ts (0 errors) ==== + declare module "baz" { + export { T } from "foo"; // Also allowed. + } \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesReExportType.js b/tests/baselines/reference/isolatedModulesReExportType.js index 545e5a81a8a..5924dd249e7 100644 --- a/tests/baselines/reference/isolatedModulesReExportType.js +++ b/tests/baselines/reference/isolatedModulesReExportType.js @@ -9,7 +9,17 @@ export class C {} //// [exportEqualsT.ts] declare type T = number; export = T; - + +//// [bar.d.ts] +export type T = number; + +//// [index.d.ts] +export { T } from "./bar"; // In a declaration file, so not an error. + +//// [index.d.ts] +declare module "baz" { + export { T } from "foo"; // Also allowed. +} //// [user.ts] // Error, can't re-export something that's only a type. diff --git a/tests/baselines/reference/jsdocInTypeScript.errors.txt b/tests/baselines/reference/jsdocInTypeScript.errors.txt index 621aa4677b4..ec3b7eab4b4 100644 --- a/tests/baselines/reference/jsdocInTypeScript.errors.txt +++ b/tests/baselines/reference/jsdocInTypeScript.errors.txt @@ -3,9 +3,10 @@ tests/cases/compiler/jsdocInTypeScript.ts(23,33): error TS2362: The left-hand si tests/cases/compiler/jsdocInTypeScript.ts(25,3): error TS2345: Argument of type '1' is not assignable to parameter of type 'boolean'. tests/cases/compiler/jsdocInTypeScript.ts(25,15): error TS2339: Property 'length' does not exist on type 'number'. tests/cases/compiler/jsdocInTypeScript.ts(30,3): error TS2339: Property 'x' does not exist on type '{}'. +tests/cases/compiler/jsdocInTypeScript.ts(42,12): error TS2503: Cannot find namespace 'N'. -==== tests/cases/compiler/jsdocInTypeScript.ts (5 errors) ==== +==== tests/cases/compiler/jsdocInTypeScript.ts (6 errors) ==== // JSDoc typedef tags are not bound TypeScript files. /** @typedef {function} T */ declare const x: T; @@ -43,7 +44,21 @@ tests/cases/compiler/jsdocInTypeScript.ts(30,3): error TS2339: Property 'x' does // @type has no effect either. /** @type {{ x?: number }} */ const z = {}; - z.x = 1; + z.x = 1; // Error ~ !!! error TS2339: Property 'x' does not exist on type '{}'. + + // @template tag should not interfere with constraint or default. + /** @template T */ + interface I {} + + /** @template T */ + function tem(t: T): I { return {}; } + + let i: I; // Should succeed thanks to type parameter default + + /** @typedef {string} N.Str */ + import M = N; // Error: @typedef does not create namespaces in TypeScript code. + ~ +!!! error TS2503: Cannot find namespace 'N'. \ No newline at end of file diff --git a/tests/baselines/reference/jsdocInTypeScript.js b/tests/baselines/reference/jsdocInTypeScript.js index 29782e92592..3e653f0859a 100644 --- a/tests/baselines/reference/jsdocInTypeScript.js +++ b/tests/baselines/reference/jsdocInTypeScript.js @@ -28,7 +28,19 @@ f(1); f(true).length; // @type has no effect either. /** @type {{ x?: number }} */ const z = {}; -z.x = 1; +z.x = 1; // Error + +// @template tag should not interfere with constraint or default. +/** @template T */ +interface I {} + +/** @template T */ +function tem(t: T): I { return {}; } + +let i: I; // Should succeed thanks to type parameter default + +/** @typedef {string} N.Str */ +import M = N; // Error: @typedef does not create namespaces in TypeScript code. //// [jsdocInTypeScript.js] @@ -50,4 +62,9 @@ f(true).length; // @type has no effect either. /** @type {{ x?: number }} */ var z = {}; -z.x = 1; +z.x = 1; // Error +/** @template T */ +function tem(t) { return {}; } +var i; // Should succeed thanks to type parameter default +/** @typedef {string} N.Str */ +var M = N; // Error: @typedef does not create namespaces in TypeScript code. diff --git a/tests/baselines/reference/jsdocTemplateTag.symbols b/tests/baselines/reference/jsdocTemplateTag.symbols new file mode 100644 index 00000000000..699e93339ed --- /dev/null +++ b/tests/baselines/reference/jsdocTemplateTag.symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/jsdoc/jsdocTemplateTag.ts === +/** + * @param {T} a + * @template T + */ +function f(a: T) { +>f : Symbol(f, Decl(jsdocTemplateTag.ts, 0, 0)) +>T : Symbol(T, Decl(jsdocTemplateTag.ts, 4, 11)) +>a : Symbol(a, Decl(jsdocTemplateTag.ts, 4, 14)) +>T : Symbol(T, Decl(jsdocTemplateTag.ts, 4, 11)) + + return () => a +>a : Symbol(a, Decl(jsdocTemplateTag.ts, 4, 14)) +} +let n = f(1)() +>n : Symbol(n, Decl(jsdocTemplateTag.ts, 7, 3)) +>f : Symbol(f, Decl(jsdocTemplateTag.ts, 0, 0)) + +/** + * @param {T} a + * @template T + * @returns {function(): T} + */ +function g(a: T) { +>g : Symbol(g, Decl(jsdocTemplateTag.ts, 7, 14)) +>T : Symbol(T, Decl(jsdocTemplateTag.ts, 14, 11)) +>a : Symbol(a, Decl(jsdocTemplateTag.ts, 14, 14)) +>T : Symbol(T, Decl(jsdocTemplateTag.ts, 14, 11)) + + return () => a +>a : Symbol(a, Decl(jsdocTemplateTag.ts, 14, 14)) +} +let s = g('hi')() +>s : Symbol(s, Decl(jsdocTemplateTag.ts, 17, 3)) +>g : Symbol(g, Decl(jsdocTemplateTag.ts, 7, 14)) + diff --git a/tests/baselines/reference/jsdocTemplateTag.types b/tests/baselines/reference/jsdocTemplateTag.types new file mode 100644 index 00000000000..72b0529d97e --- /dev/null +++ b/tests/baselines/reference/jsdocTemplateTag.types @@ -0,0 +1,44 @@ +=== tests/cases/conformance/jsdoc/jsdocTemplateTag.ts === +/** + * @param {T} a + * @template T + */ +function f(a: T) { +>f : (a: T) => () => T +>T : T +>a : T +>T : T + + return () => a +>() => a : () => T +>a : T +} +let n = f(1)() +>n : number +>f(1)() : number +>f(1) : () => number +>f : (a: T) => () => T +>1 : 1 + +/** + * @param {T} a + * @template T + * @returns {function(): T} + */ +function g(a: T) { +>g : (a: T) => () => T +>T : T +>a : T +>T : T + + return () => a +>() => a : () => T +>a : T +} +let s = g('hi')() +>s : string +>g('hi')() : string +>g('hi') : () => string +>g : (a: T) => () => T +>'hi' : "hi" + diff --git a/tests/baselines/reference/mismatchedGenericArguments1.errors.txt b/tests/baselines/reference/mismatchedGenericArguments1.errors.txt new file mode 100644 index 00000000000..13618c926ef --- /dev/null +++ b/tests/baselines/reference/mismatchedGenericArguments1.errors.txt @@ -0,0 +1,40 @@ +tests/cases/compiler/mismatchedGenericArguments1.ts(4,7): error TS2420: Class 'C' incorrectly implements interface 'IFoo'. + Types of property 'foo' are incompatible. + Type '(x: string) => number' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'string'. +tests/cases/compiler/mismatchedGenericArguments1.ts(10,7): error TS2420: Class 'C2' incorrectly implements interface 'IFoo'. + Types of property 'foo' are incompatible. + Type '(x: string) => number' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'string'. + + +==== tests/cases/compiler/mismatchedGenericArguments1.ts (2 errors) ==== + interface IFoo { + foo(x: T): T; + } + class C implements IFoo { + ~ +!!! error TS2420: Class 'C' incorrectly implements interface 'IFoo'. +!!! error TS2420: Types of property 'foo' are incompatible. +!!! error TS2420: Type '(x: string) => number' is not assignable to type '(x: T) => T'. +!!! error TS2420: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2420: Type 'T' is not assignable to type 'string'. + foo(x: string): number { + return null; + } + } + + class C2 implements IFoo { + ~~ +!!! error TS2420: Class 'C2' incorrectly implements interface 'IFoo'. +!!! error TS2420: Types of property 'foo' are incompatible. +!!! error TS2420: Type '(x: string) => number' is not assignable to type '(x: T) => T'. +!!! error TS2420: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2420: Type 'T' is not assignable to type 'string'. + foo(x: string): number { + return null; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/neverUnionIntersection.js b/tests/baselines/reference/neverUnionIntersection.js new file mode 100644 index 00000000000..1e84e4b003f --- /dev/null +++ b/tests/baselines/reference/neverUnionIntersection.js @@ -0,0 +1,17 @@ +//// [neverUnionIntersection.ts] +type T01 = string | never; +type T02 = string & never; +type T03 = string | number | never; +type T04 = string & number & never; +type T05 = any | never; +type T06 = any & never; +type T07 = undefined | never; +type T08 = undefined & never; +type T09 = null | never; +type T10 = null & never; +type T11 = { a: string } | never; +type T12 = { a: string } & never; + + +//// [neverUnionIntersection.js] +"use strict"; diff --git a/tests/baselines/reference/neverUnionIntersection.symbols b/tests/baselines/reference/neverUnionIntersection.symbols new file mode 100644 index 00000000000..0f56c1b3157 --- /dev/null +++ b/tests/baselines/reference/neverUnionIntersection.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/types/never/neverUnionIntersection.ts === +type T01 = string | never; +>T01 : Symbol(T01, Decl(neverUnionIntersection.ts, 0, 0)) + +type T02 = string & never; +>T02 : Symbol(T02, Decl(neverUnionIntersection.ts, 0, 26)) + +type T03 = string | number | never; +>T03 : Symbol(T03, Decl(neverUnionIntersection.ts, 1, 26)) + +type T04 = string & number & never; +>T04 : Symbol(T04, Decl(neverUnionIntersection.ts, 2, 35)) + +type T05 = any | never; +>T05 : Symbol(T05, Decl(neverUnionIntersection.ts, 3, 35)) + +type T06 = any & never; +>T06 : Symbol(T06, Decl(neverUnionIntersection.ts, 4, 23)) + +type T07 = undefined | never; +>T07 : Symbol(T07, Decl(neverUnionIntersection.ts, 5, 23)) + +type T08 = undefined & never; +>T08 : Symbol(T08, Decl(neverUnionIntersection.ts, 6, 29)) + +type T09 = null | never; +>T09 : Symbol(T09, Decl(neverUnionIntersection.ts, 7, 29)) + +type T10 = null & never; +>T10 : Symbol(T10, Decl(neverUnionIntersection.ts, 8, 24)) + +type T11 = { a: string } | never; +>T11 : Symbol(T11, Decl(neverUnionIntersection.ts, 9, 24)) +>a : Symbol(a, Decl(neverUnionIntersection.ts, 10, 12)) + +type T12 = { a: string } & never; +>T12 : Symbol(T12, Decl(neverUnionIntersection.ts, 10, 33)) +>a : Symbol(a, Decl(neverUnionIntersection.ts, 11, 12)) + diff --git a/tests/baselines/reference/neverUnionIntersection.types b/tests/baselines/reference/neverUnionIntersection.types new file mode 100644 index 00000000000..4f578052e9c --- /dev/null +++ b/tests/baselines/reference/neverUnionIntersection.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/types/never/neverUnionIntersection.ts === +type T01 = string | never; +>T01 : string + +type T02 = string & never; +>T02 : never + +type T03 = string | number | never; +>T03 : T03 + +type T04 = string & number & never; +>T04 : never + +type T05 = any | never; +>T05 : any + +type T06 = any & never; +>T06 : never + +type T07 = undefined | never; +>T07 : undefined + +type T08 = undefined & never; +>T08 : never + +type T09 = null | never; +>T09 : null +>null : null + +type T10 = null & never; +>T10 : never +>null : null + +type T11 = { a: string } | never; +>T11 : { a: string; } +>a : string + +type T12 = { a: string } & never; +>T12 : never +>a : string + diff --git a/tests/baselines/reference/noStrictGenericChecks.js b/tests/baselines/reference/noStrictGenericChecks.js new file mode 100644 index 00000000000..485fdc6bd3b --- /dev/null +++ b/tests/baselines/reference/noStrictGenericChecks.js @@ -0,0 +1,15 @@ +//// [noStrictGenericChecks.ts] +type A = (x: T, y: U) => [T, U]; +type B = (x: S, y: S) => [S, S]; + +function f(a: A, b: B) { + a = b; // Error disabled here + b = a; // Ok +} + + +//// [noStrictGenericChecks.js] +function f(a, b) { + a = b; // Error disabled here + b = a; // Ok +} diff --git a/tests/baselines/reference/noStrictGenericChecks.symbols b/tests/baselines/reference/noStrictGenericChecks.symbols new file mode 100644 index 00000000000..5244cc44f2e --- /dev/null +++ b/tests/baselines/reference/noStrictGenericChecks.symbols @@ -0,0 +1,38 @@ +=== tests/cases/compiler/noStrictGenericChecks.ts === +type A = (x: T, y: U) => [T, U]; +>A : Symbol(A, Decl(noStrictGenericChecks.ts, 0, 0)) +>T : Symbol(T, Decl(noStrictGenericChecks.ts, 0, 10)) +>U : Symbol(U, Decl(noStrictGenericChecks.ts, 0, 12)) +>x : Symbol(x, Decl(noStrictGenericChecks.ts, 0, 16)) +>T : Symbol(T, Decl(noStrictGenericChecks.ts, 0, 10)) +>y : Symbol(y, Decl(noStrictGenericChecks.ts, 0, 21)) +>U : Symbol(U, Decl(noStrictGenericChecks.ts, 0, 12)) +>T : Symbol(T, Decl(noStrictGenericChecks.ts, 0, 10)) +>U : Symbol(U, Decl(noStrictGenericChecks.ts, 0, 12)) + +type B = (x: S, y: S) => [S, S]; +>B : Symbol(B, Decl(noStrictGenericChecks.ts, 0, 38)) +>S : Symbol(S, Decl(noStrictGenericChecks.ts, 1, 10)) +>x : Symbol(x, Decl(noStrictGenericChecks.ts, 1, 13)) +>S : Symbol(S, Decl(noStrictGenericChecks.ts, 1, 10)) +>y : Symbol(y, Decl(noStrictGenericChecks.ts, 1, 18)) +>S : Symbol(S, Decl(noStrictGenericChecks.ts, 1, 10)) +>S : Symbol(S, Decl(noStrictGenericChecks.ts, 1, 10)) +>S : Symbol(S, Decl(noStrictGenericChecks.ts, 1, 10)) + +function f(a: A, b: B) { +>f : Symbol(f, Decl(noStrictGenericChecks.ts, 1, 35)) +>a : Symbol(a, Decl(noStrictGenericChecks.ts, 3, 11)) +>A : Symbol(A, Decl(noStrictGenericChecks.ts, 0, 0)) +>b : Symbol(b, Decl(noStrictGenericChecks.ts, 3, 16)) +>B : Symbol(B, Decl(noStrictGenericChecks.ts, 0, 38)) + + a = b; // Error disabled here +>a : Symbol(a, Decl(noStrictGenericChecks.ts, 3, 11)) +>b : Symbol(b, Decl(noStrictGenericChecks.ts, 3, 16)) + + b = a; // Ok +>b : Symbol(b, Decl(noStrictGenericChecks.ts, 3, 16)) +>a : Symbol(a, Decl(noStrictGenericChecks.ts, 3, 11)) +} + diff --git a/tests/baselines/reference/noStrictGenericChecks.types b/tests/baselines/reference/noStrictGenericChecks.types new file mode 100644 index 00000000000..0509c22859a --- /dev/null +++ b/tests/baselines/reference/noStrictGenericChecks.types @@ -0,0 +1,40 @@ +=== tests/cases/compiler/noStrictGenericChecks.ts === +type A = (x: T, y: U) => [T, U]; +>A : A +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>T : T +>U : U + +type B = (x: S, y: S) => [S, S]; +>B : B +>S : S +>x : S +>S : S +>y : S +>S : S +>S : S +>S : S + +function f(a: A, b: B) { +>f : (a: A, b: B) => void +>a : A +>A : A +>b : B +>B : B + + a = b; // Error disabled here +>a = b : B +>a : A +>b : B + + b = a; // Ok +>b = a : A +>b : B +>a : A +} + diff --git a/tests/baselines/reference/objectLiteralFunctionArgContextualTyping2.errors.txt b/tests/baselines/reference/objectLiteralFunctionArgContextualTyping2.errors.txt index b967b227809..0117d2c0c8c 100644 --- a/tests/baselines/reference/objectLiteralFunctionArgContextualTyping2.errors.txt +++ b/tests/baselines/reference/objectLiteralFunctionArgContextualTyping2.errors.txt @@ -4,12 +4,12 @@ tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(9,4): error TS Property 'doStuff' is missing in type '{ value: string; }'. tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(10,17): error TS2345: Argument of type '{ value: string; what: number; }' is not assignable to parameter of type 'I2'. Object literal may only specify known properties, and 'what' does not exist in type 'I2'. -tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(11,4): error TS2345: Argument of type '{ toString: (s: any) => any; }' is not assignable to parameter of type 'I2'. - Property 'value' is missing in type '{ toString: (s: any) => any; }'. -tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(12,4): error TS2345: Argument of type '{ toString: (s: string) => string; }' is not assignable to parameter of type 'I2'. - Property 'value' is missing in type '{ toString: (s: string) => string; }'. -tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(13,4): error TS2345: Argument of type '{ value: string; toString: (s: any) => any; }' is not assignable to parameter of type 'I2'. - Property 'doStuff' is missing in type '{ value: string; toString: (s: any) => any; }'. +tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(11,6): error TS2345: Argument of type '{ toString: (s: any) => any; }' is not assignable to parameter of type 'I2'. + Object literal may only specify known properties, and 'toString' does not exist in type 'I2'. +tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(12,6): error TS2345: Argument of type '{ toString: (s: string) => string; }' is not assignable to parameter of type 'I2'. + Object literal may only specify known properties, and 'toString' does not exist in type 'I2'. +tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(13,17): error TS2345: Argument of type '{ value: string; toString: (s: any) => any; }' is not assignable to parameter of type 'I2'. + Object literal may only specify known properties, and 'toString' does not exist in type 'I2'. ==== tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts (6 errors) ==== @@ -33,14 +33,14 @@ tests/cases/compiler/objectLiteralFunctionArgContextualTyping2.ts(13,4): error T !!! error TS2345: Argument of type '{ value: string; what: number; }' is not assignable to parameter of type 'I2'. !!! error TS2345: Object literal may only specify known properties, and 'what' does not exist in type 'I2'. f2({ toString: (s) => s }) - ~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ toString: (s: any) => any; }' is not assignable to parameter of type 'I2'. -!!! error TS2345: Property 'value' is missing in type '{ toString: (s: any) => any; }'. +!!! error TS2345: Object literal may only specify known properties, and 'toString' does not exist in type 'I2'. f2({ toString: (s: string) => s }) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ toString: (s: string) => string; }' is not assignable to parameter of type 'I2'. -!!! error TS2345: Property 'value' is missing in type '{ toString: (s: string) => string; }'. +!!! error TS2345: Object literal may only specify known properties, and 'toString' does not exist in type 'I2'. f2({ value: '', toString: (s) => s.uhhh }) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ value: string; toString: (s: any) => any; }' is not assignable to parameter of type 'I2'. -!!! error TS2345: Property 'doStuff' is missing in type '{ value: string; toString: (s: any) => any; }'. \ No newline at end of file +!!! error TS2345: Object literal may only specify known properties, and 'toString' does not exist in type 'I2'. \ No newline at end of file diff --git a/tests/baselines/reference/promiseTypeInference.errors.txt b/tests/baselines/reference/promiseTypeInference.errors.txt new file mode 100644 index 00000000000..fab56c73375 --- /dev/null +++ b/tests/baselines/reference/promiseTypeInference.errors.txt @@ -0,0 +1,31 @@ +tests/cases/compiler/promiseTypeInference.ts(10,34): error TS2345: Argument of type '(s: string) => IPromise' is not assignable to parameter of type '(value: string) => number | PromiseLike'. + Type 'IPromise' is not assignable to type 'number | PromiseLike'. + Type 'IPromise' is not assignable to type 'PromiseLike'. + Types of property 'then' are incompatible. + Type '(success?: (value: number) => IPromise) => IPromise' is not assignable to type '(onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => PromiseLike'. + Types of parameters 'success' and 'onfulfilled' are incompatible. + Type 'TResult1 | PromiseLike' is not assignable to type 'IPromise'. + Type 'TResult1' is not assignable to type 'IPromise'. + + +==== tests/cases/compiler/promiseTypeInference.ts (1 errors) ==== + declare class Promise { + then(success?: (value: T) => Promise): Promise; + } + interface IPromise { + then(success?: (value: T) => IPromise): IPromise; + } + declare function load(name: string): Promise; + declare function convert(s: string): IPromise; + + var $$x = load("something").then(s => convert(s)); + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(s: string) => IPromise' is not assignable to parameter of type '(value: string) => number | PromiseLike'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'number | PromiseLike'. +!!! error TS2345: Type 'IPromise' is not assignable to type 'PromiseLike'. +!!! error TS2345: Types of property 'then' are incompatible. +!!! error TS2345: Type '(success?: (value: number) => IPromise) => IPromise' is not assignable to type '(onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => PromiseLike'. +!!! error TS2345: Types of parameters 'success' and 'onfulfilled' are incompatible. +!!! error TS2345: Type 'TResult1 | PromiseLike' is not assignable to type 'IPromise'. +!!! error TS2345: Type 'TResult1' is not assignable to type 'IPromise'. + \ No newline at end of file diff --git a/tests/baselines/reference/returnInfiniteIntersection.js b/tests/baselines/reference/returnInfiniteIntersection.js new file mode 100644 index 00000000000..db77d21f32d --- /dev/null +++ b/tests/baselines/reference/returnInfiniteIntersection.js @@ -0,0 +1,15 @@ +//// [returnInfiniteIntersection.ts] +function recursive() { + let x = (subkey: T) => recursive(); + return x as typeof x & { p }; +} + +let result = recursive()(1) + + +//// [returnInfiniteIntersection.js] +function recursive() { + var x = function (subkey) { return recursive(); }; + return x; +} +var result = recursive()(1); diff --git a/tests/baselines/reference/returnInfiniteIntersection.symbols b/tests/baselines/reference/returnInfiniteIntersection.symbols new file mode 100644 index 00000000000..125861ac78d --- /dev/null +++ b/tests/baselines/reference/returnInfiniteIntersection.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/returnInfiniteIntersection.ts === +function recursive() { +>recursive : Symbol(recursive, Decl(returnInfiniteIntersection.ts, 0, 0)) + + let x = (subkey: T) => recursive(); +>x : Symbol(x, Decl(returnInfiniteIntersection.ts, 1, 7)) +>T : Symbol(T, Decl(returnInfiniteIntersection.ts, 1, 13)) +>subkey : Symbol(subkey, Decl(returnInfiniteIntersection.ts, 1, 16)) +>T : Symbol(T, Decl(returnInfiniteIntersection.ts, 1, 13)) +>recursive : Symbol(recursive, Decl(returnInfiniteIntersection.ts, 0, 0)) + + return x as typeof x & { p }; +>x : Symbol(x, Decl(returnInfiniteIntersection.ts, 1, 7)) +>x : Symbol(x, Decl(returnInfiniteIntersection.ts, 1, 7)) +>p : Symbol(p, Decl(returnInfiniteIntersection.ts, 2, 28)) +} + +let result = recursive()(1) +>result : Symbol(result, Decl(returnInfiniteIntersection.ts, 5, 3)) +>recursive : Symbol(recursive, Decl(returnInfiniteIntersection.ts, 0, 0)) + diff --git a/tests/baselines/reference/returnInfiniteIntersection.types b/tests/baselines/reference/returnInfiniteIntersection.types new file mode 100644 index 00000000000..e7ca48a69d1 --- /dev/null +++ b/tests/baselines/reference/returnInfiniteIntersection.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/returnInfiniteIntersection.ts === +function recursive() { +>recursive : () => ((subkey: T) => any & { p: any; }) & { p: any; } + + let x = (subkey: T) => recursive(); +>x : (subkey: T) => any & { p: any; } +>(subkey: T) => recursive() : (subkey: T) => any & { p: any; } +>T : T +>subkey : T +>T : T +>recursive() : ((subkey: T) => any & { p: any; }) & { p: any; } +>recursive : () => ((subkey: T) => any & { p: any; }) & { p: any; } + + return x as typeof x & { p }; +>x as typeof x & { p } : ((subkey: T) => any & { p: any; }) & { p: any; } +>x : (subkey: T) => any & { p: any; } +>x : (subkey: T) => any & { p: any; } +>p : any +} + +let result = recursive()(1) +>result : ((subkey: T) => any & { p: any; }) & { p: any; } +>recursive()(1) : ((subkey: T) => any & { p: any; }) & { p: any; } +>recursive() : ((subkey: T) => any & { p: any; }) & { p: any; } +>recursive : () => ((subkey: T) => any & { p: any; }) & { p: any; } +>1 : 1 + diff --git a/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.js b/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.js new file mode 100644 index 00000000000..24a27fb919a --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.js @@ -0,0 +1,14 @@ +//// [sourceMapValidationVarInDownLevelGenerator.ts] +function * f() { + var x = 1, y; +} + +//// [sourceMapValidationVarInDownLevelGenerator.js] +function f() { + var x, y; + return __generator(this, function (_a) { + x = 1; + return [2 /*return*/]; + }); +} +//# sourceMappingURL=sourceMapValidationVarInDownLevelGenerator.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.js.map b/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.js.map new file mode 100644 index 00000000000..293f445a6fd --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.js.map @@ -0,0 +1,2 @@ +//// [sourceMapValidationVarInDownLevelGenerator.js.map] +{"version":3,"file":"sourceMapValidationVarInDownLevelGenerator.js","sourceRoot":"","sources":["sourceMapValidationVarInDownLevelGenerator.ts"],"names":[],"mappings":"AAAA;;;QACQ,CAAC,GAAG,CAAC,CAAI;;;CAChB"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.sourcemap.txt b/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.sourcemap.txt new file mode 100644 index 00000000000..8fe7af32307 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.sourcemap.txt @@ -0,0 +1,47 @@ +=================================================================== +JsFile: sourceMapValidationVarInDownLevelGenerator.js +mapUrl: sourceMapValidationVarInDownLevelGenerator.js.map +sourceRoot: +sources: sourceMapValidationVarInDownLevelGenerator.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/sourceMapValidationVarInDownLevelGenerator.js +sourceFile:sourceMapValidationVarInDownLevelGenerator.ts +------------------------------------------------------------------- +>>>function f() { +1 > +2 >^^^^^^^^^^^^^^-> +1 > +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +--- +>>> var x, y; +>>> return __generator(this, function (_a) { +>>> x = 1; +1->^^^^^^^^ +2 > ^ +3 > ^^^ +4 > ^ +5 > ^ +6 > ^^^^^^^^^^^^^^^^^-> +1->function * f() { + > var +2 > x +3 > = +4 > 1 +5 > , y; +1->Emitted(4, 9) Source(2, 9) + SourceIndex(0) +2 >Emitted(4, 10) Source(2, 10) + SourceIndex(0) +3 >Emitted(4, 13) Source(2, 13) + SourceIndex(0) +4 >Emitted(4, 14) Source(2, 14) + SourceIndex(0) +5 >Emitted(4, 15) Source(2, 18) + SourceIndex(0) +--- +>>> return [2 /*return*/]; +>>> }); +>>>} +1->^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> + >} +1->Emitted(7, 2) Source(3, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=sourceMapValidationVarInDownLevelGenerator.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.symbols b/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.symbols new file mode 100644 index 00000000000..99c9c4d714a --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/sourceMapValidationVarInDownLevelGenerator.ts === +function * f() { +>f : Symbol(f, Decl(sourceMapValidationVarInDownLevelGenerator.ts, 0, 0)) + + var x = 1, y; +>x : Symbol(x, Decl(sourceMapValidationVarInDownLevelGenerator.ts, 1, 7)) +>y : Symbol(y, Decl(sourceMapValidationVarInDownLevelGenerator.ts, 1, 14)) +} diff --git a/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.types b/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.types new file mode 100644 index 00000000000..cac2f03d8e4 --- /dev/null +++ b/tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/sourceMapValidationVarInDownLevelGenerator.ts === +function * f() { +>f : () => IterableIterator + + var x = 1, y; +>x : number +>1 : 1 +>y : any +} diff --git a/tests/baselines/reference/subtypingWithCallSignatures2.types b/tests/baselines/reference/subtypingWithCallSignatures2.types index 86c65702b98..029262380d8 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures2.types +++ b/tests/baselines/reference/subtypingWithCallSignatures2.types @@ -325,20 +325,20 @@ var r1arg2 = (x: number) => [1]; >1 : 1 var r1 = foo1(r1arg1); // any, return types are not subtype of first overload ->r1 : any ->foo1(r1arg1) : any +>r1 : (x: number) => number[] +>foo1(r1arg1) : (x: number) => number[] >foo1 : { (a: (x: number) => number[]): (x: number) => number[]; (a: any): any; } >r1arg1 : (x: T) => T[] var r1a = [r1arg2, r1arg1]; // generic signature, subtype in both directions ->r1a : ((x: T) => T[])[] ->[r1arg2, r1arg1] : ((x: T) => T[])[] +>r1a : ((x: number) => number[])[] +>[r1arg2, r1arg1] : ((x: number) => number[])[] >r1arg2 : (x: number) => number[] >r1arg1 : (x: T) => T[] var r1b = [r1arg1, r1arg2]; // generic signature, subtype in both directions ->r1b : ((x: T) => T[])[] ->[r1arg1, r1arg2] : ((x: T) => T[])[] +>r1b : ((x: number) => number[])[] +>[r1arg1, r1arg2] : ((x: number) => number[])[] >r1arg1 : (x: T) => T[] >r1arg2 : (x: number) => number[] @@ -365,14 +365,14 @@ var r2 = foo2(r2arg1); >r2arg1 : (x: T) => string[] var r2a = [r2arg1, r2arg2]; ->r2a : ((x: T) => string[])[] ->[r2arg1, r2arg2] : ((x: T) => string[])[] +>r2a : ((x: number) => string[])[] +>[r2arg1, r2arg2] : ((x: number) => string[])[] >r2arg1 : (x: T) => string[] >r2arg2 : (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : ((x: T) => string[])[] ->[r2arg2, r2arg1] : ((x: T) => string[])[] +>r2b : ((x: number) => string[])[] +>[r2arg2, r2arg1] : ((x: number) => string[])[] >r2arg2 : (x: number) => string[] >r2arg1 : (x: T) => string[] @@ -396,14 +396,14 @@ var r3 = foo3(r3arg1); >r3arg1 : (x: T) => T var r3a = [r3arg1, r3arg2]; ->r3a : ((x: T) => T)[] ->[r3arg1, r3arg2] : ((x: T) => T)[] +>r3a : ((x: number) => void)[] +>[r3arg1, r3arg2] : ((x: number) => void)[] >r3arg1 : (x: T) => T >r3arg2 : (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : ((x: T) => T)[] ->[r3arg2, r3arg1] : ((x: T) => T)[] +>r3b : ((x: number) => void)[] +>[r3arg2, r3arg1] : ((x: number) => void)[] >r3arg2 : (x: number) => void >r3arg1 : (x: T) => T @@ -426,20 +426,20 @@ var r4arg2 = (x: string, y: number) => ''; >'' : "" var r4 = foo4(r4arg1); // any ->r4 : any ->foo4(r4arg1) : any +>r4 : (x: string, y: number) => string +>foo4(r4arg1) : (x: string, y: number) => string >foo4 : { (a: (x: string, y: number) => string): (x: string, y: number) => string; (a: any): any; } >r4arg1 : (x: T, y: U) => T var r4a = [r4arg1, r4arg2]; ->r4a : ((x: T, y: U) => T)[] ->[r4arg1, r4arg2] : ((x: T, y: U) => T)[] +>r4a : ((x: string, y: number) => string)[] +>[r4arg1, r4arg2] : ((x: string, y: number) => string)[] >r4arg1 : (x: T, y: U) => T >r4arg2 : (x: string, y: number) => string var r4b = [r4arg2, r4arg1]; ->r4b : ((x: T, y: U) => T)[] ->[r4arg2, r4arg1] : ((x: T, y: U) => T)[] +>r4b : ((x: string, y: number) => string)[] +>[r4arg2, r4arg1] : ((x: string, y: number) => string)[] >r4arg2 : (x: string, y: number) => string >r4arg1 : (x: T, y: U) => T @@ -464,20 +464,20 @@ var r5arg2 = (x: (arg: string) => number) => ''; >'' : "" var r5 = foo5(r5arg1); // any ->r5 : any ->foo5(r5arg1) : any +>r5 : (x: (arg: string) => number) => string +>foo5(r5arg1) : (x: (arg: string) => number) => string >foo5 : { (a: (x: (arg: string) => number) => string): (x: (arg: string) => number) => string; (a: any): any; } >r5arg1 : (x: (arg: T) => U) => T var r5a = [r5arg1, r5arg2]; ->r5a : ((x: (arg: T) => U) => T)[] ->[r5arg1, r5arg2] : ((x: (arg: T) => U) => T)[] +>r5a : ((x: (arg: string) => number) => string)[] +>[r5arg1, r5arg2] : ((x: (arg: string) => number) => string)[] >r5arg1 : (x: (arg: T) => U) => T >r5arg2 : (x: (arg: string) => number) => string var r5b = [r5arg2, r5arg1]; ->r5b : ((x: (arg: T) => U) => T)[] ->[r5arg2, r5arg1] : ((x: (arg: T) => U) => T)[] +>r5b : ((x: (arg: string) => number) => string)[] +>[r5arg2, r5arg1] : ((x: (arg: string) => number) => string)[] >r5arg2 : (x: (arg: string) => number) => string >r5arg1 : (x: (arg: T) => U) => T @@ -508,20 +508,20 @@ var r6arg2 = (x: (arg: Base) => Derived) => null; >null : null var r6 = foo6(r6arg1); // any ->r6 : any ->foo6(r6arg1) : any +>r6 : (x: (arg: Base) => Derived) => Base +>foo6(r6arg1) : (x: (arg: Base) => Derived) => Base >foo6 : { (a: (x: (arg: Base) => Derived) => Base): (x: (arg: Base) => Derived) => Base; (a: any): any; } >r6arg1 : (x: (arg: T) => U) => T var r6a = [r6arg1, r6arg2]; ->r6a : ((x: (arg: T) => U) => T)[] ->[r6arg1, r6arg2] : ((x: (arg: T) => U) => T)[] +>r6a : ((x: (arg: Base) => Derived) => Base)[] +>[r6arg1, r6arg2] : ((x: (arg: Base) => Derived) => Base)[] >r6arg1 : (x: (arg: T) => U) => T >r6arg2 : (x: (arg: Base) => Derived) => Base var r6b = [r6arg2, r6arg1]; ->r6b : ((x: (arg: T) => U) => T)[] ->[r6arg2, r6arg1] : ((x: (arg: T) => U) => T)[] +>r6b : ((x: (arg: Base) => Derived) => Base)[] +>[r6arg2, r6arg1] : ((x: (arg: Base) => Derived) => Base)[] >r6arg2 : (x: (arg: Base) => Derived) => Base >r6arg1 : (x: (arg: T) => U) => T @@ -558,20 +558,20 @@ var r7arg2 = (x: (arg: Base) => Derived) => (r: Base) => null; >null : null var r7 = foo7(r7arg1); // any ->r7 : any ->foo7(r7arg1) : any +>r7 : (x: (arg: Base) => Derived) => (r: Base) => Derived +>foo7(r7arg1) : (x: (arg: Base) => Derived) => (r: Base) => Derived >foo7 : { (a: (x: (arg: Base) => Derived) => (r: Base) => Derived): (x: (arg: Base) => Derived) => (r: Base) => Derived; (a: any): any; } >r7arg1 : (x: (arg: T) => U) => (r: T) => U var r7a = [r7arg1, r7arg2]; ->r7a : ((x: (arg: T) => U) => (r: T) => U)[] ->[r7arg1, r7arg2] : ((x: (arg: T) => U) => (r: T) => U)[] +>r7a : ((x: (arg: Base) => Derived) => (r: Base) => Derived)[] +>[r7arg1, r7arg2] : ((x: (arg: Base) => Derived) => (r: Base) => Derived)[] >r7arg1 : (x: (arg: T) => U) => (r: T) => U >r7arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived var r7b = [r7arg2, r7arg1]; ->r7b : ((x: (arg: T) => U) => (r: T) => U)[] ->[r7arg2, r7arg1] : ((x: (arg: T) => U) => (r: T) => U)[] +>r7b : ((x: (arg: Base) => Derived) => (r: Base) => Derived)[] +>[r7arg2, r7arg1] : ((x: (arg: Base) => Derived) => (r: Base) => Derived)[] >r7arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived >r7arg1 : (x: (arg: T) => U) => (r: T) => U @@ -616,20 +616,20 @@ var r8arg2 = (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base >null : null var r8 = foo8(r8arg1); // any ->r8 : any ->foo8(r8arg1) : any +>r8 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived +>foo8(r8arg1) : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >foo8 : { (a: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived): (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; (a: any): any; } >r8arg1 : (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U var r8a = [r8arg1, r8arg2]; ->r8a : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] ->[r8arg1, r8arg2] : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] +>r8a : ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived)[] +>[r8arg1, r8arg2] : ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived)[] >r8arg1 : (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U >r8arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived var r8b = [r8arg2, r8arg1]; ->r8b : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] ->[r8arg2, r8arg1] : ((x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U)[] +>r8b : ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived)[] +>[r8arg2, r8arg1] : ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived)[] >r8arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r8arg1 : (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U @@ -675,20 +675,20 @@ var r9arg2 = (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base >null : null var r9 = foo9(r9arg1); // any ->r9 : any ->foo9(r9arg1) : any +>r9 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived +>foo9(r9arg1) : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >foo9 : { (a: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived): (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; (a: any): 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) | ((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))[] +>r9a : ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived)[] +>[r9arg1, 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 >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) | ((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))[] +>r9b : ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived)[] +>[r9arg2, r9arg1] : ((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 @@ -713,20 +713,20 @@ var r10arg2 = (...x: Derived[]) => null; >null : null var r10 = foo10(r10arg1); // any ->r10 : any ->foo10(r10arg1) : any +>r10 : (...x: Derived[]) => Derived +>foo10(r10arg1) : (...x: Derived[]) => Derived >foo10 : { (a: (...x: Derived[]) => Derived): (...x: Derived[]) => Derived; (a: any): any; } >r10arg1 : (...x: T[]) => T var r10a = [r10arg1, r10arg2]; ->r10a : ((...x: T[]) => T)[] ->[r10arg1, r10arg2] : ((...x: T[]) => T)[] +>r10a : ((...x: Derived[]) => Derived)[] +>[r10arg1, r10arg2] : ((...x: Derived[]) => Derived)[] >r10arg1 : (...x: T[]) => T >r10arg2 : (...x: Derived[]) => Derived var r10b = [r10arg2, r10arg1]; ->r10b : ((...x: T[]) => T)[] ->[r10arg2, r10arg1] : ((...x: T[]) => T)[] +>r10b : ((...x: Derived[]) => Derived)[] +>[r10arg2, r10arg1] : ((...x: Derived[]) => Derived)[] >r10arg2 : (...x: Derived[]) => Derived >r10arg1 : (...x: T[]) => T @@ -754,20 +754,20 @@ var r11arg2 = (x: { foo: string }, y: { foo: string; bar: string }) => nul >null : null var r11 = foo11(r11arg1); // any ->r11 : any ->foo11(r11arg1) : any +>r11 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base +>foo11(r11arg1) : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >foo11 : { (a: (x: { foo: string; }, y: { foo: string; bar: string; }) => Base): (x: { foo: string; }, y: { foo: string; bar: string; }) => Base; (a: any): any; } >r11arg1 : (x: T, y: T) => T var r11a = [r11arg1, r11arg2]; ->r11a : ((x: T, y: T) => T)[] ->[r11arg1, r11arg2] : ((x: T, y: T) => T)[] +>r11a : ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] +>[r11arg1, r11arg2] : ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] >r11arg1 : (x: T, y: T) => T >r11arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base var r11b = [r11arg2, r11arg1]; ->r11b : ((x: T, y: T) => T)[] ->[r11arg2, r11arg1] : ((x: T, y: T) => T)[] +>r11b : ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] +>[r11arg2, r11arg1] : ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] >r11arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r11arg1 : (x: T, y: T) => T @@ -808,14 +808,14 @@ var r12 = foo12(r12arg1); // any >r12arg1 : (x: Base[], y: T) => Derived[] var r12a = [r12arg1, r12arg2]; ->r12a : ((x: Base[], y: T) => Derived[])[] ->[r12arg1, r12arg2] : ((x: Base[], y: T) => Derived[])[] +>r12a : ((x: Base[], y: Derived2[]) => Derived[])[] +>[r12arg1, r12arg2] : ((x: Base[], y: Derived2[]) => Derived[])[] >r12arg1 : (x: Base[], y: T) => Derived[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : ((x: Base[], y: T) => Derived[])[] ->[r12arg2, r12arg1] : ((x: Base[], y: T) => Derived[])[] +>r12b : ((x: Base[], y: Derived2[]) => Derived[])[] +>[r12arg2, r12arg1] : ((x: Base[], y: Derived2[]) => Derived[])[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : (x: Base[], y: T) => Derived[] @@ -847,20 +847,20 @@ var r13arg2 = (x: Array, y: Array) => >null; >null : null var r13 = foo13(r13arg1); // any ->r13 : any ->foo13(r13arg1) : any +>r13 : (x: Base[], y: Derived[]) => Derived[] +>foo13(r13arg1) : (x: Base[], y: Derived[]) => Derived[] >foo13 : { (a: (x: Base[], y: Derived[]) => Derived[]): (x: Base[], y: Derived[]) => Derived[]; (a: any): any; } >r13arg1 : (x: Base[], y: T) => T var r13a = [r13arg1, r13arg2]; ->r13a : ((x: Base[], y: T) => T)[] ->[r13arg1, r13arg2] : ((x: Base[], y: T) => T)[] +>r13a : ((x: Base[], y: Derived[]) => Derived[])[] +>[r13arg1, r13arg2] : ((x: Base[], y: Derived[]) => Derived[])[] >r13arg1 : (x: Base[], y: T) => T >r13arg2 : (x: Base[], y: Derived[]) => Derived[] var r13b = [r13arg2, r13arg1]; ->r13b : ((x: Base[], y: T) => T)[] ->[r13arg2, r13arg1] : ((x: Base[], y: T) => T)[] +>r13b : ((x: Base[], y: Derived[]) => Derived[])[] +>[r13arg2, r13arg1] : ((x: Base[], y: Derived[]) => Derived[])[] >r13arg2 : (x: Base[], y: Derived[]) => Derived[] >r13arg1 : (x: Base[], y: T) => T @@ -888,20 +888,20 @@ var r14arg2 = (x: { a: string; b: number }) => null; >null : null var r14 = foo14(r14arg1); // any ->r14 : any ->foo14(r14arg1) : any +>r14 : (x: { a: string; b: number; }) => Object +>foo14(r14arg1) : (x: { a: string; b: number; }) => Object >foo14 : { (a: (x: { a: string; b: number; }) => Object): (x: { a: string; b: number; }) => Object; (a: any): any; } >r14arg1 : (x: { a: T; b: T; }) => T var r14a = [r14arg1, r14arg2]; ->r14a : ((x: { a: T; b: T; }) => T)[] ->[r14arg1, r14arg2] : ((x: { a: T; b: T; }) => T)[] +>r14a : ((x: { a: string; b: number; }) => Object)[] +>[r14arg1, r14arg2] : ((x: { a: string; b: number; }) => Object)[] >r14arg1 : (x: { a: T; b: T; }) => T >r14arg2 : (x: { a: string; b: number; }) => Object var r14b = [r14arg2, r14arg1]; ->r14b : ((x: { a: T; b: T; }) => T)[] ->[r14arg2, r14arg1] : ((x: { a: T; b: T; }) => T)[] +>r14b : ((x: { a: string; b: number; }) => Object)[] +>[r14arg2, r14arg1] : ((x: { a: string; b: number; }) => Object)[] >r14arg2 : (x: { a: string; b: number; }) => Object >r14arg1 : (x: { a: T; b: T; }) => T diff --git a/tests/baselines/reference/subtypingWithCallSignatures3.types b/tests/baselines/reference/subtypingWithCallSignatures3.types index 6abc7567efb..99953d899f2 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures3.types +++ b/tests/baselines/reference/subtypingWithCallSignatures3.types @@ -206,8 +206,8 @@ module Errors { >a2 : any var r1 = foo2((x: T) => null); // any ->r1 : any ->foo2((x: T) => null) : any +>r1 : (x: number) => string[] +>foo2((x: T) => null) : (x: number) => string[] >foo2 : { (a2: (x: number) => string[]): (x: number) => string[]; (a2: any): any; } >(x: T) => null : (x: T) => U[] >T : T @@ -219,8 +219,8 @@ module Errors { >null : null var r1a = [(x: number) => [''], (x: T) => null]; ->r1a : ((x: T) => U[])[] ->[(x: number) => [''], (x: T) => null] : ((x: T) => U[])[] +>r1a : ((x: number) => string[])[] +>[(x: number) => [''], (x: T) => null] : ((x: number) => string[])[] >(x: number) => [''] : (x: number) => string[] >x : number >[''] : string[] @@ -235,8 +235,8 @@ module Errors { >null : null var r1b = [(x: T) => null, (x: number) => ['']]; ->r1b : ((x: T) => U[])[] ->[(x: T) => null, (x: number) => ['']] : ((x: T) => U[])[] +>r1b : ((x: number) => string[])[] +>[(x: T) => null, (x: number) => ['']] : ((x: number) => string[])[] >(x: T) => null : (x: T) => U[] >T : T >U : U @@ -285,20 +285,20 @@ module Errors { >null : null var r2 = foo7(r2arg); // any ->r2 : any ->foo7(r2arg) : any +>r2 : (x: (arg: Base) => Derived) => (r: Base) => Derived2 +>foo7(r2arg) : (x: (arg: Base) => Derived) => (r: Base) => Derived2 >foo7 : { (a2: (x: (arg: Base) => Derived) => (r: Base) => Derived2): (x: (arg: Base) => Derived) => (r: Base) => Derived2; (a2: any): any; } >r2arg : (x: (arg: T) => U) => (r: T) => V var r2a = [r2arg2, r2arg]; ->r2a : ((x: (arg: T) => U) => (r: T) => V)[] ->[r2arg2, r2arg] : ((x: (arg: T) => U) => (r: T) => V)[] +>r2a : ((x: (arg: Base) => Derived) => (r: Base) => Derived2)[] +>[r2arg2, r2arg] : ((x: (arg: Base) => Derived) => (r: Base) => Derived2)[] >r2arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived2 >r2arg : (x: (arg: T) => U) => (r: T) => V var r2b = [r2arg, r2arg2]; ->r2b : ((x: (arg: T) => U) => (r: T) => V)[] ->[r2arg, r2arg2] : ((x: (arg: T) => U) => (r: T) => V)[] +>r2b : ((x: (arg: Base) => Derived) => (r: Base) => Derived2)[] +>[r2arg, r2arg2] : ((x: (arg: Base) => Derived) => (r: Base) => Derived2)[] >r2arg : (x: (arg: T) => U) => (r: T) => V >r2arg2 : (x: (arg: Base) => Derived) => (r: Base) => Derived2 @@ -381,20 +381,20 @@ module Errors { >null : null var r4 = foo10(r4arg); // any ->r4 : any ->foo10(r4arg) : any +>r4 : (...x: Base[]) => Base +>foo10(r4arg) : (...x: Base[]) => Base >foo10 : { (a2: (...x: Base[]) => Base): (...x: Base[]) => Base; (a2: any): any; } >r4arg : (...x: T[]) => T var r4a = [r4arg2, r4arg]; ->r4a : ((...x: T[]) => T)[] ->[r4arg2, r4arg] : ((...x: T[]) => T)[] +>r4a : ((...x: Base[]) => Base)[] +>[r4arg2, r4arg] : ((...x: Base[]) => Base)[] >r4arg2 : (...x: Base[]) => Base >r4arg : (...x: T[]) => T var r4b = [r4arg, r4arg2]; ->r4b : ((...x: T[]) => T)[] ->[r4arg, r4arg2] : ((...x: T[]) => T)[] +>r4b : ((...x: Base[]) => Base)[] +>[r4arg, r4arg2] : ((...x: Base[]) => Base)[] >r4arg : (...x: T[]) => T >r4arg2 : (...x: Base[]) => Base @@ -424,20 +424,20 @@ module Errors { >null : null var r5 = foo11(r5arg); // any ->r5 : any ->foo11(r5arg) : any +>r5 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base +>foo11(r5arg) : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >foo11 : { (a2: (x: { foo: string; }, y: { foo: string; bar: string; }) => Base): (x: { foo: string; }, y: { foo: string; bar: string; }) => Base; (a2: any): any; } >r5arg : (x: T, y: T) => T var r5a = [r5arg2, r5arg]; ->r5a : ((x: T, y: T) => T)[] ->[r5arg2, r5arg] : ((x: T, y: T) => T)[] +>r5a : ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] +>[r5arg2, r5arg] : ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] >r5arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r5arg : (x: T, y: T) => T var r5b = [r5arg, r5arg2]; ->r5b : ((x: T, y: T) => T)[] ->[r5arg, r5arg2] : ((x: T, y: T) => T)[] +>r5b : ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] +>[r5arg, r5arg2] : ((x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] >r5arg : (x: T, y: T) => T >r5arg2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base @@ -478,14 +478,14 @@ module Errors { >r6arg : (x: Base[], y: Derived2[]) => Derived[] var r6a = [r6arg2, r6arg]; ->r6a : ((x: Base[], y: Base[]) => T)[] ->[r6arg2, r6arg] : ((x: Base[], y: Base[]) => T)[] +>r6a : ((x: Base[], y: Derived2[]) => Derived[])[] +>[r6arg2, r6arg] : ((x: Base[], y: Derived2[]) => Derived[])[] >r6arg2 : (x: Base[], y: Base[]) => T >r6arg : (x: Base[], y: Derived2[]) => Derived[] var r6b = [r6arg, r6arg2]; ->r6b : ((x: Base[], y: Base[]) => T)[] ->[r6arg, r6arg2] : ((x: Base[], y: Base[]) => T)[] +>r6b : ((x: Base[], y: Derived2[]) => Derived[])[] +>[r6arg, r6arg2] : ((x: Base[], y: Derived2[]) => Derived[])[] >r6arg : (x: Base[], y: Derived2[]) => Derived[] >r6arg2 : (x: Base[], y: Base[]) => T @@ -517,14 +517,14 @@ module Errors { >r7arg : (x: { a: T; b: T; }) => T var r7a = [r7arg2, r7arg]; ->r7a : ((x: { a: T; b: T; }) => T)[] ->[r7arg2, r7arg] : ((x: { a: T; b: T; }) => T)[] +>r7a : (((x: { a: T; b: T; }) => T) | ((x: { a: string; b: number; }) => number))[] +>[r7arg2, r7arg] : (((x: { a: T; b: T; }) => T) | ((x: { a: string; b: number; }) => number))[] >r7arg2 : (x: { a: string; b: number; }) => number >r7arg : (x: { a: T; b: T; }) => T var r7b = [r7arg, r7arg2]; ->r7b : ((x: { a: T; b: T; }) => T)[] ->[r7arg, r7arg2] : ((x: { a: T; b: T; }) => T)[] +>r7b : (((x: { a: T; b: T; }) => T) | ((x: { a: string; b: number; }) => number))[] +>[r7arg, r7arg2] : (((x: { a: T; b: T; }) => T) | ((x: { a: string; b: number; }) => number))[] >r7arg : (x: { a: T; b: T; }) => T >r7arg2 : (x: { a: string; b: number; }) => number @@ -541,20 +541,20 @@ module Errors { >1 : 1 var r7c = foo15(r7arg3); // (x: { a: string; b: number }) => number): number; ->r7c : (x: { a: string; b: number; }) => number ->foo15(r7arg3) : (x: { a: string; b: number; }) => number +>r7c : any +>foo15(r7arg3) : any >foo15 : { (a2: (x: { a: string; b: number; }) => number): (x: { a: string; b: number; }) => number; (a2: any): any; } >r7arg3 : (x: { a: T; b: T; }) => number var r7d = [r7arg2, r7arg3]; ->r7d : ((x: { a: string; b: number; }) => number)[] ->[r7arg2, r7arg3] : ((x: { a: string; b: number; }) => number)[] +>r7d : (((x: { a: string; b: number; }) => number) | ((x: { a: T; b: T; }) => number))[] +>[r7arg2, r7arg3] : (((x: { a: string; b: number; }) => number) | ((x: { a: T; b: T; }) => number))[] >r7arg2 : (x: { a: string; b: number; }) => number >r7arg3 : (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : ((x: { a: string; b: number; }) => number)[] ->[r7arg3, r7arg2] : ((x: { a: string; b: number; }) => number)[] +>r7e : (((x: { a: string; b: number; }) => number) | ((x: { a: T; b: T; }) => number))[] +>[r7arg3, r7arg2] : (((x: { a: string; b: number; }) => number) | ((x: { a: T; b: T; }) => number))[] >r7arg3 : (x: { a: T; b: T; }) => number >r7arg2 : (x: { a: string; b: number; }) => number @@ -620,8 +620,8 @@ module WithGenericSignaturesInBaseType { >'' : "" var r2 = foo2(r2arg2); // (x:T) => T[] since we can infer from generic signatures now ->r2 : (x: T) => T[] ->foo2(r2arg2) : (x: T) => T[] +>r2 : any +>foo2(r2arg2) : any >foo2 : { (a2: (x: T) => T[]): (x: T) => T[]; (a2: any): any; } >r2arg2 : (x: T) => string[] diff --git a/tests/baselines/reference/subtypingWithCallSignatures4.types b/tests/baselines/reference/subtypingWithCallSignatures4.types index 5926636289a..3751b9c73dd 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures4.types +++ b/tests/baselines/reference/subtypingWithCallSignatures4.types @@ -317,14 +317,14 @@ var r3 = foo3(r3arg); >r3arg : (x: T) => T var r3a = [r3arg, r3arg2]; ->r3a : ((x: T) => T)[] ->[r3arg, r3arg2] : ((x: T) => T)[] +>r3a : ((x: T) => void)[] +>[r3arg, r3arg2] : ((x: T) => void)[] >r3arg : (x: T) => T >r3arg2 : (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : ((x: T) => T)[] ->[r3arg2, r3arg] : ((x: T) => T)[] +>r3b : ((x: T) => void)[] +>[r3arg2, r3arg] : ((x: T) => void)[] >r3arg2 : (x: T) => void >r3arg : (x: T) => T @@ -543,14 +543,14 @@ var r15 = foo15(r15arg); >r15arg : (x: { a: U; b: V; }) => U[] var r15a = [r15arg, r15arg2]; ->r15a : ((x: { a: U; b: V; }) => U[])[] ->[r15arg, r15arg2] : ((x: { a: U; b: V; }) => U[])[] +>r15a : ((x: { a: T; b: T; }) => T[])[] +>[r15arg, r15arg2] : ((x: { a: T; b: T; }) => T[])[] >r15arg : (x: { a: U; b: V; }) => U[] >r15arg2 : (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : ((x: { a: U; b: V; }) => U[])[] ->[r15arg2, r15arg] : ((x: { a: U; b: V; }) => U[])[] +>r15b : ((x: { a: T; b: T; }) => T[])[] +>[r15arg2, r15arg] : ((x: { a: T; b: T; }) => T[])[] >r15arg2 : (x: { a: T; b: T; }) => T[] >r15arg : (x: { a: U; b: V; }) => U[] diff --git a/tests/baselines/reference/subtypingWithCallSignaturesWithSpecializedSignatures.errors.txt b/tests/baselines/reference/subtypingWithCallSignaturesWithSpecializedSignatures.errors.txt index da742fcd69c..b1719689606 100644 --- a/tests/baselines/reference/subtypingWithCallSignaturesWithSpecializedSignatures.errors.txt +++ b/tests/baselines/reference/subtypingWithCallSignaturesWithSpecializedSignatures.errors.txt @@ -2,9 +2,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Types of property 'a' are incompatible. Type '(x: string) => string' is not assignable to type '{ (x: "a"): number; (x: string): number; }'. Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesWithSpecializedSignatures.ts(76,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. + Types of property 'a2' are incompatible. + Type '(x: T) => string' is not assignable to type '(x: T) => T'. + Type 'string' is not assignable to type 'T'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesWithSpecializedSignatures.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesWithSpecializedSignatures.ts (2 errors) ==== // same as subtypingWithCallSignatures but with additional specialized signatures that should not affect the results module CallSignature { @@ -86,6 +90,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW // S's interface I3 extends Base2 { + ~~ +!!! error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type '(x: T) => string' is not assignable to type '(x: T) => T'. +!!! error TS2430: Type 'string' is not assignable to type 'T'. // N's a2: (x: T) => string; // error because base returns non-void; } diff --git a/tests/baselines/reference/subtypingWithConstructSignatures2.types b/tests/baselines/reference/subtypingWithConstructSignatures2.types index d723a367ecb..9bf8c58edb6 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures2.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures2.types @@ -320,20 +320,20 @@ var r1arg2: new (x: number) => number[]; >x : number var r1 = foo1(r1arg1); // any, return types are not subtype of first overload ->r1 : any ->foo1(r1arg1) : any +>r1 : new (x: number) => number[] +>foo1(r1arg1) : new (x: number) => number[] >foo1 : { (a: new (x: number) => number[]): new (x: number) => number[]; (a: any): any; } >r1arg1 : new (x: T) => T[] var r1a = [r1arg2, r1arg1]; // generic signature, subtype in both directions ->r1a : (new (x: T) => T[])[] ->[r1arg2, r1arg1] : (new (x: T) => T[])[] +>r1a : (new (x: number) => number[])[] +>[r1arg2, r1arg1] : (new (x: number) => number[])[] >r1arg2 : new (x: number) => number[] >r1arg1 : new (x: T) => T[] var r1b = [r1arg1, r1arg2]; // generic signature, subtype in both directions ->r1b : (new (x: T) => T[])[] ->[r1arg1, r1arg2] : (new (x: T) => T[])[] +>r1b : (new (x: number) => number[])[] +>[r1arg1, r1arg2] : (new (x: number) => number[])[] >r1arg1 : new (x: T) => T[] >r1arg2 : new (x: number) => number[] @@ -354,14 +354,14 @@ var r2 = foo2(r2arg1); >r2arg1 : new (x: T) => string[] var r2a = [r2arg1, r2arg2]; ->r2a : (new (x: T) => string[])[] ->[r2arg1, r2arg2] : (new (x: T) => string[])[] +>r2a : (new (x: number) => string[])[] +>[r2arg1, r2arg2] : (new (x: number) => string[])[] >r2arg1 : new (x: T) => string[] >r2arg2 : new (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : (new (x: T) => string[])[] ->[r2arg2, r2arg1] : (new (x: T) => string[])[] +>r2b : (new (x: number) => string[])[] +>[r2arg2, r2arg1] : (new (x: number) => string[])[] >r2arg2 : new (x: number) => string[] >r2arg1 : new (x: T) => string[] @@ -383,14 +383,14 @@ var r3 = foo3(r3arg1); >r3arg1 : new (x: T) => T var r3a = [r3arg1, r3arg2]; ->r3a : (new (x: T) => T)[] ->[r3arg1, r3arg2] : (new (x: T) => T)[] +>r3a : (new (x: number) => void)[] +>[r3arg1, r3arg2] : (new (x: number) => void)[] >r3arg1 : new (x: T) => T >r3arg2 : new (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : (new (x: T) => T)[] ->[r3arg2, r3arg1] : (new (x: T) => T)[] +>r3b : (new (x: number) => void)[] +>[r3arg2, r3arg1] : (new (x: number) => void)[] >r3arg2 : new (x: number) => void >r3arg1 : new (x: T) => T @@ -410,20 +410,20 @@ var r4arg2: new (x: string, y: number) => string; >y : number var r4 = foo4(r4arg1); // any ->r4 : any ->foo4(r4arg1) : any +>r4 : new (x: string, y: number) => string +>foo4(r4arg1) : new (x: string, y: number) => string >foo4 : { (a: new (x: string, y: number) => string): new (x: string, y: number) => string; (a: any): any; } >r4arg1 : new (x: T, y: U) => T var r4a = [r4arg1, r4arg2]; ->r4a : (new (x: T, y: U) => T)[] ->[r4arg1, r4arg2] : (new (x: T, y: U) => T)[] +>r4a : (new (x: string, y: number) => string)[] +>[r4arg1, r4arg2] : (new (x: string, y: number) => string)[] >r4arg1 : new (x: T, y: U) => T >r4arg2 : new (x: string, y: number) => string var r4b = [r4arg2, r4arg1]; ->r4b : (new (x: T, y: U) => T)[] ->[r4arg2, r4arg1] : (new (x: T, y: U) => T)[] +>r4b : (new (x: string, y: number) => string)[] +>[r4arg2, r4arg1] : (new (x: string, y: number) => string)[] >r4arg2 : new (x: string, y: number) => string >r4arg1 : new (x: T, y: U) => T @@ -443,20 +443,20 @@ var r5arg2: new (x: new (arg: string) => number) => string; >arg : string var r5 = foo5(r5arg1); // any ->r5 : any ->foo5(r5arg1) : any +>r5 : new (x: new (arg: string) => number) => string +>foo5(r5arg1) : new (x: new (arg: string) => number) => string >foo5 : { (a: new (x: new (arg: string) => number) => string): new (x: new (arg: string) => number) => string; (a: any): any; } >r5arg1 : new (x: new (arg: T) => U) => T var r5a = [r5arg1, r5arg2]; ->r5a : (new (x: new (arg: T) => U) => T)[] ->[r5arg1, r5arg2] : (new (x: new (arg: T) => U) => T)[] +>r5a : (new (x: new (arg: string) => number) => string)[] +>[r5arg1, r5arg2] : (new (x: new (arg: string) => number) => string)[] >r5arg1 : new (x: new (arg: T) => U) => T >r5arg2 : new (x: new (arg: string) => number) => string var r5b = [r5arg2, r5arg1]; ->r5b : (new (x: new (arg: T) => U) => T)[] ->[r5arg2, r5arg1] : (new (x: new (arg: T) => U) => T)[] +>r5b : (new (x: new (arg: string) => number) => string)[] +>[r5arg2, r5arg1] : (new (x: new (arg: string) => number) => string)[] >r5arg2 : new (x: new (arg: string) => number) => string >r5arg1 : new (x: new (arg: T) => U) => T @@ -481,20 +481,20 @@ var r6arg2: new (x: new (arg: Base) => Derived) => Base; >Base : Base var r6 = foo6(r6arg1); // any ->r6 : any ->foo6(r6arg1) : any +>r6 : new (x: new (arg: Base) => Derived) => Base +>foo6(r6arg1) : new (x: new (arg: Base) => Derived) => Base >foo6 : { (a: new (x: new (arg: Base) => Derived) => Base): new (x: new (arg: Base) => Derived) => Base; (a: any): any; } >r6arg1 : new (x: new (arg: T) => U) => T var r6a = [r6arg1, r6arg2]; ->r6a : (new (x: new (arg: T) => U) => T)[] ->[r6arg1, r6arg2] : (new (x: new (arg: T) => U) => T)[] +>r6a : (new (x: new (arg: Base) => Derived) => Base)[] +>[r6arg1, r6arg2] : (new (x: new (arg: Base) => Derived) => Base)[] >r6arg1 : new (x: new (arg: T) => U) => T >r6arg2 : new (x: new (arg: Base) => Derived) => Base var r6b = [r6arg2, r6arg1]; ->r6b : (new (x: new (arg: T) => U) => T)[] ->[r6arg2, r6arg1] : (new (x: new (arg: T) => U) => T)[] +>r6b : (new (x: new (arg: Base) => Derived) => Base)[] +>[r6arg2, r6arg1] : (new (x: new (arg: Base) => Derived) => Base)[] >r6arg2 : new (x: new (arg: Base) => Derived) => Base >r6arg1 : new (x: new (arg: T) => U) => T @@ -523,20 +523,20 @@ var r7arg2: new (x: new (arg: Base) => Derived) => new (r: Base) => Derived; >Derived : Derived var r7 = foo7(r7arg1); // any ->r7 : any ->foo7(r7arg1) : any +>r7 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived +>foo7(r7arg1) : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived >foo7 : { (a: new (x: new (arg: Base) => Derived) => new (r: Base) => Derived): new (x: new (arg: Base) => Derived) => new (r: Base) => Derived; (a: any): any; } >r7arg1 : new (x: new (arg: T) => U) => new (r: T) => U var r7a = [r7arg1, r7arg2]; ->r7a : (new (x: new (arg: T) => U) => new (r: T) => U)[] ->[r7arg1, r7arg2] : (new (x: new (arg: T) => U) => new (r: T) => U)[] +>r7a : (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived)[] +>[r7arg1, r7arg2] : (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived)[] >r7arg1 : new (x: new (arg: T) => U) => new (r: T) => U >r7arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived var r7b = [r7arg2, r7arg1]; ->r7b : (new (x: new (arg: T) => U) => new (r: T) => U)[] ->[r7arg2, r7arg1] : (new (x: new (arg: T) => U) => new (r: T) => U)[] +>r7b : (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived)[] +>[r7arg2, r7arg1] : (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived)[] >r7arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived >r7arg1 : new (x: new (arg: T) => U) => new (r: T) => U @@ -573,20 +573,20 @@ var r8arg2: new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) >Derived : Derived var r8 = foo8(r8arg1); // any ->r8 : any ->foo8(r8arg1) : any +>r8 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived +>foo8(r8arg1) : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >foo8 : { (a: new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived): new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived; (a: any): any; } >r8arg1 : new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U var r8a = [r8arg1, r8arg2]; ->r8a : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] ->[r8arg1, r8arg2] : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] +>r8a : (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived)[] +>[r8arg1, r8arg2] : (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived)[] >r8arg1 : new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U >r8arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived var r8b = [r8arg2, r8arg1]; ->r8b : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] ->[r8arg2, r8arg1] : (new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U)[] +>r8b : (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived)[] +>[r8arg2, r8arg1] : (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived)[] >r8arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r8arg1 : new (x: new (arg: T) => U, y: new (arg2: T) => U) => new (r: T) => U @@ -656,20 +656,20 @@ var r10arg2: new (...x: Derived[]) => Derived; >Derived : Derived var r10 = foo10(r10arg1); // any ->r10 : any ->foo10(r10arg1) : any +>r10 : new (...x: Derived[]) => Derived +>foo10(r10arg1) : new (...x: Derived[]) => Derived >foo10 : { (a: new (...x: Derived[]) => Derived): new (...x: Derived[]) => Derived; (a: any): any; } >r10arg1 : new (...x: T[]) => T var r10a = [r10arg1, r10arg2]; ->r10a : (new (...x: T[]) => T)[] ->[r10arg1, r10arg2] : (new (...x: T[]) => T)[] +>r10a : (new (...x: Derived[]) => Derived)[] +>[r10arg1, r10arg2] : (new (...x: Derived[]) => Derived)[] >r10arg1 : new (...x: T[]) => T >r10arg2 : new (...x: Derived[]) => Derived var r10b = [r10arg2, r10arg1]; ->r10b : (new (...x: T[]) => T)[] ->[r10arg2, r10arg1] : (new (...x: T[]) => T)[] +>r10b : (new (...x: Derived[]) => Derived)[] +>[r10arg2, r10arg1] : (new (...x: Derived[]) => Derived)[] >r10arg2 : new (...x: Derived[]) => Derived >r10arg1 : new (...x: T[]) => T @@ -693,20 +693,20 @@ var r11arg2: new (x: { foo: string }, y: { foo: string; bar: string }) => Base; >Base : Base var r11 = foo11(r11arg1); // any ->r11 : any ->foo11(r11arg1) : any +>r11 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base +>foo11(r11arg1) : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >foo11 : { (a: new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base): new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base; (a: any): any; } >r11arg1 : new (x: T, y: T) => T var r11a = [r11arg1, r11arg2]; ->r11a : (new (x: T, y: T) => T)[] ->[r11arg1, r11arg2] : (new (x: T, y: T) => T)[] +>r11a : (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] +>[r11arg1, r11arg2] : (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] >r11arg1 : new (x: T, y: T) => T >r11arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base var r11b = [r11arg2, r11arg1]; ->r11b : (new (x: T, y: T) => T)[] ->[r11arg2, r11arg1] : (new (x: T, y: T) => T)[] +>r11b : (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] +>[r11arg2, r11arg1] : (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] >r11arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r11arg1 : new (x: T, y: T) => T @@ -741,14 +741,14 @@ var r12 = foo12(r12arg1); // any >r12arg1 : new (x: Base[], y: T) => Derived[] var r12a = [r12arg1, r12arg2]; ->r12a : (new (x: Base[], y: T) => Derived[])[] ->[r12arg1, r12arg2] : (new (x: Base[], y: T) => Derived[])[] +>r12a : (new (x: Base[], y: Derived2[]) => Derived[])[] +>[r12arg1, r12arg2] : (new (x: Base[], y: Derived2[]) => Derived[])[] >r12arg1 : new (x: Base[], y: T) => Derived[] >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : (new (x: Base[], y: T) => Derived[])[] ->[r12arg2, r12arg1] : (new (x: Base[], y: T) => Derived[])[] +>r12b : (new (x: Base[], y: Derived2[]) => Derived[])[] +>[r12arg2, r12arg1] : (new (x: Base[], y: Derived2[]) => Derived[])[] >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : new (x: Base[], y: T) => Derived[] @@ -776,20 +776,20 @@ var r13arg2: new (x: Array, y: Array) => Array; >Derived : Derived var r13 = foo13(r13arg1); // any ->r13 : any ->foo13(r13arg1) : any +>r13 : new (x: Base[], y: Derived[]) => Derived[] +>foo13(r13arg1) : new (x: Base[], y: Derived[]) => Derived[] >foo13 : { (a: new (x: Base[], y: Derived[]) => Derived[]): new (x: Base[], y: Derived[]) => Derived[]; (a: any): any; } >r13arg1 : new (x: Base[], y: T) => T var r13a = [r13arg1, r13arg2]; ->r13a : (new (x: Base[], y: T) => T)[] ->[r13arg1, r13arg2] : (new (x: Base[], y: T) => T)[] +>r13a : (new (x: Base[], y: Derived[]) => Derived[])[] +>[r13arg1, r13arg2] : (new (x: Base[], y: Derived[]) => Derived[])[] >r13arg1 : new (x: Base[], y: T) => T >r13arg2 : new (x: Base[], y: Derived[]) => Derived[] var r13b = [r13arg2, r13arg1]; ->r13b : (new (x: Base[], y: T) => T)[] ->[r13arg2, r13arg1] : (new (x: Base[], y: T) => T)[] +>r13b : (new (x: Base[], y: Derived[]) => Derived[])[] +>[r13arg2, r13arg1] : (new (x: Base[], y: Derived[]) => Derived[])[] >r13arg2 : new (x: Base[], y: Derived[]) => Derived[] >r13arg1 : new (x: Base[], y: T) => T @@ -811,20 +811,20 @@ var r14arg2: new (x: { a: string; b: number }) => Object; >Object : Object var r14 = foo14(r14arg1); // any ->r14 : any ->foo14(r14arg1) : any +>r14 : new (x: { a: string; b: number; }) => Object +>foo14(r14arg1) : new (x: { a: string; b: number; }) => Object >foo14 : { (a: new (x: { a: string; b: number; }) => Object): new (x: { a: string; b: number; }) => Object; (a: any): any; } >r14arg1 : new (x: { a: T; b: T; }) => T var r14a = [r14arg1, r14arg2]; ->r14a : (new (x: { a: T; b: T; }) => T)[] ->[r14arg1, r14arg2] : (new (x: { a: T; b: T; }) => T)[] +>r14a : (new (x: { a: string; b: number; }) => Object)[] +>[r14arg1, r14arg2] : (new (x: { a: string; b: number; }) => Object)[] >r14arg1 : new (x: { a: T; b: T; }) => T >r14arg2 : new (x: { a: string; b: number; }) => Object var r14b = [r14arg2, r14arg1]; ->r14b : (new (x: { a: T; b: T; }) => T)[] ->[r14arg2, r14arg1] : (new (x: { a: T; b: T; }) => T)[] +>r14b : (new (x: { a: string; b: number; }) => Object)[] +>[r14arg2, r14arg1] : (new (x: { a: string; b: number; }) => Object)[] >r14arg2 : new (x: { a: string; b: number; }) => Object >r14arg1 : new (x: { a: T; b: T; }) => T diff --git a/tests/baselines/reference/subtypingWithConstructSignatures3.types b/tests/baselines/reference/subtypingWithConstructSignatures3.types index b0f0680c7a0..c5cd2569763 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures3.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures3.types @@ -218,20 +218,20 @@ module Errors { >x : number var r1 = foo2(r1arg1); // any ->r1 : any ->foo2(r1arg1) : any +>r1 : new (x: number) => string[] +>foo2(r1arg1) : new (x: number) => string[] >foo2 : { (a2: new (x: number) => string[]): new (x: number) => string[]; (a2: any): any; } >r1arg1 : new (x: T) => U[] var r1a = [r1arg2, r1arg1]; ->r1a : (new (x: T) => U[])[] ->[r1arg2, r1arg1] : (new (x: T) => U[])[] +>r1a : (new (x: number) => string[])[] +>[r1arg2, r1arg1] : (new (x: number) => string[])[] >r1arg2 : new (x: number) => string[] >r1arg1 : new (x: T) => U[] var r1b = [r1arg1, r1arg2]; ->r1b : (new (x: T) => U[])[] ->[r1arg1, r1arg2] : (new (x: T) => U[])[] +>r1b : (new (x: number) => string[])[] +>[r1arg1, r1arg2] : (new (x: number) => string[])[] >r1arg1 : new (x: T) => U[] >r1arg2 : new (x: number) => string[] @@ -262,20 +262,20 @@ module Errors { >Derived2 : Derived2 var r2 = foo7(r2arg1); // any ->r2 : any ->foo7(r2arg1) : any +>r2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2 +>foo7(r2arg1) : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2 >foo7 : { (a2: new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2): new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2; (a2: any): any; } >r2arg1 : new (x: new (arg: T) => U) => new (r: T) => V var r2a = [r2arg2, r2arg1]; ->r2a : (new (x: new (arg: T) => U) => new (r: T) => V)[] ->[r2arg2, r2arg1] : (new (x: new (arg: T) => U) => new (r: T) => V)[] +>r2a : (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2)[] +>[r2arg2, r2arg1] : (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2)[] >r2arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2 >r2arg1 : new (x: new (arg: T) => U) => new (r: T) => V var r2b = [r2arg1, r2arg2]; ->r2b : (new (x: new (arg: T) => U) => new (r: T) => V)[] ->[r2arg1, r2arg2] : (new (x: new (arg: T) => U) => new (r: T) => V)[] +>r2b : (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2)[] +>[r2arg1, r2arg2] : (new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2)[] >r2arg1 : new (x: new (arg: T) => U) => new (r: T) => V >r2arg2 : new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2 @@ -344,20 +344,20 @@ module Errors { >Base : Base var r4 = foo10(r4arg1); // any ->r4 : any ->foo10(r4arg1) : any +>r4 : new (...x: Base[]) => Base +>foo10(r4arg1) : new (...x: Base[]) => Base >foo10 : { (a2: new (...x: Base[]) => Base): new (...x: Base[]) => Base; (a2: any): any; } >r4arg1 : new (...x: T[]) => T var r4a = [r4arg2, r4arg1]; ->r4a : (new (...x: T[]) => T)[] ->[r4arg2, r4arg1] : (new (...x: T[]) => T)[] +>r4a : (new (...x: Base[]) => Base)[] +>[r4arg2, r4arg1] : (new (...x: Base[]) => Base)[] >r4arg2 : new (...x: Base[]) => Base >r4arg1 : new (...x: T[]) => T var r4b = [r4arg1, r4arg2]; ->r4b : (new (...x: T[]) => T)[] ->[r4arg1, r4arg2] : (new (...x: T[]) => T)[] +>r4b : (new (...x: Base[]) => Base)[] +>[r4arg1, r4arg2] : (new (...x: Base[]) => Base)[] >r4arg1 : new (...x: T[]) => T >r4arg2 : new (...x: Base[]) => Base @@ -381,20 +381,20 @@ module Errors { >Base : Base var r5 = foo11(r5arg1); // any ->r5 : any ->foo11(r5arg1) : any +>r5 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base +>foo11(r5arg1) : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >foo11 : { (a2: new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base): new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base; (a2: any): any; } >r5arg1 : new (x: T, y: T) => T var r5a = [r5arg2, r5arg1]; ->r5a : (new (x: T, y: T) => T)[] ->[r5arg2, r5arg1] : (new (x: T, y: T) => T)[] +>r5a : (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] +>[r5arg2, r5arg1] : (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] >r5arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base >r5arg1 : new (x: T, y: T) => T var r5b = [r5arg1, r5arg2]; ->r5b : (new (x: T, y: T) => T)[] ->[r5arg1, r5arg2] : (new (x: T, y: T) => T)[] +>r5b : (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] +>[r5arg1, r5arg2] : (new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base)[] >r5arg1 : new (x: T, y: T) => T >r5arg2 : new (x: { foo: string; }, y: { foo: string; bar: string; }) => Base @@ -429,14 +429,14 @@ module Errors { >r6arg1 : new (x: Base[], y: Derived2[]) => Derived[] var r6a = [r6arg2, r6arg1]; ->r6a : (new (x: Base[], y: Base[]) => T)[] ->[r6arg2, r6arg1] : (new (x: Base[], y: Base[]) => T)[] +>r6a : (new (x: Base[], y: Derived2[]) => Derived[])[] +>[r6arg2, r6arg1] : (new (x: Base[], y: Derived2[]) => Derived[])[] >r6arg2 : new (x: Base[], y: Base[]) => T >r6arg1 : new (x: Base[], y: Derived2[]) => Derived[] var r6b = [r6arg1, r6arg2]; ->r6b : (new (x: Base[], y: Base[]) => T)[] ->[r6arg1, r6arg2] : (new (x: Base[], y: Base[]) => T)[] +>r6b : (new (x: Base[], y: Derived2[]) => Derived[])[] +>[r6arg1, r6arg2] : (new (x: Base[], y: Derived2[]) => Derived[])[] >r6arg1 : new (x: Base[], y: Derived2[]) => Derived[] >r6arg2 : new (x: Base[], y: Base[]) => T @@ -463,14 +463,14 @@ module Errors { >r7arg1 : new (x: { a: T; b: T; }) => T var r7a = [r7arg2, r7arg1]; ->r7a : (new (x: { a: T; b: T; }) => T)[] ->[r7arg2, r7arg1] : (new (x: { a: T; b: T; }) => T)[] +>r7a : ((new (x: { a: T; b: T; }) => T) | (new (x: { a: string; b: number; }) => number))[] +>[r7arg2, r7arg1] : ((new (x: { a: T; b: T; }) => T) | (new (x: { a: string; b: number; }) => number))[] >r7arg2 : new (x: { a: string; b: number; }) => number >r7arg1 : new (x: { a: T; b: T; }) => T var r7b = [r7arg1, r7arg2]; ->r7b : (new (x: { a: T; b: T; }) => T)[] ->[r7arg1, r7arg2] : (new (x: { a: T; b: T; }) => T)[] +>r7b : ((new (x: { a: T; b: T; }) => T) | (new (x: { a: string; b: number; }) => number))[] +>[r7arg1, r7arg2] : ((new (x: { a: T; b: T; }) => T) | (new (x: { a: string; b: number; }) => number))[] >r7arg1 : new (x: { a: T; b: T; }) => T >r7arg2 : new (x: { a: string; b: number; }) => number @@ -485,20 +485,20 @@ module Errors { >T : T var r7c = foo15(r7arg3); // any ->r7c : new (x: { a: string; b: number; }) => number ->foo15(r7arg3) : new (x: { a: string; b: number; }) => number +>r7c : any +>foo15(r7arg3) : any >foo15 : { (a2: new (x: { a: string; b: number; }) => number): new (x: { a: string; b: number; }) => number; (a2: any): any; } >r7arg3 : new (x: { a: T; b: T; }) => number var r7d = [r7arg2, r7arg3]; ->r7d : (new (x: { a: string; b: number; }) => number)[] ->[r7arg2, r7arg3] : (new (x: { a: string; b: number; }) => number)[] +>r7d : ((new (x: { a: string; b: number; }) => number) | (new (x: { a: T; b: T; }) => number))[] +>[r7arg2, r7arg3] : ((new (x: { a: string; b: number; }) => number) | (new (x: { a: T; b: T; }) => number))[] >r7arg2 : new (x: { a: string; b: number; }) => number >r7arg3 : new (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : (new (x: { a: string; b: number; }) => number)[] ->[r7arg3, r7arg2] : (new (x: { a: string; b: number; }) => number)[] +>r7e : ((new (x: { a: string; b: number; }) => number) | (new (x: { a: T; b: T; }) => number))[] +>[r7arg3, r7arg2] : ((new (x: { a: string; b: number; }) => number) | (new (x: { a: T; b: T; }) => number))[] >r7arg3 : new (x: { a: T; b: T; }) => number >r7arg2 : new (x: { a: string; b: number; }) => number @@ -555,8 +555,8 @@ module WithGenericSignaturesInBaseType { >T : T var r2 = foo2(r2arg2); // (x:T) => T[] since we can infer from generic signatures now ->r2 : new (x: T) => T[] ->foo2(r2arg2) : new (x: T) => T[] +>r2 : any +>foo2(r2arg2) : any >foo2 : { (a2: new (x: T) => T[]): new (x: T) => T[]; (a2: any): any; } >r2arg2 : new (x: T) => string[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures4.types b/tests/baselines/reference/subtypingWithConstructSignatures4.types index 21a40ecf7fc..5cf612ed1d0 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures4.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures4.types @@ -301,14 +301,14 @@ var r3 = foo3(r3arg); >r3arg : new (x: T) => T var r3a = [r3arg, r3arg2]; ->r3a : (new (x: T) => T)[] ->[r3arg, r3arg2] : (new (x: T) => T)[] +>r3a : (new (x: T) => void)[] +>[r3arg, r3arg2] : (new (x: T) => void)[] >r3arg : new (x: T) => T >r3arg2 : new (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : (new (x: T) => T)[] ->[r3arg2, r3arg] : (new (x: T) => T)[] +>r3b : (new (x: T) => void)[] +>[r3arg2, r3arg] : (new (x: T) => void)[] >r3arg2 : new (x: T) => void >r3arg : new (x: T) => T @@ -499,14 +499,14 @@ var r15 = foo15(r15arg); >r15arg : new (x: { a: U; b: V; }) => U[] var r15a = [r15arg, r15arg2]; ->r15a : (new (x: { a: U; b: V; }) => U[])[] ->[r15arg, r15arg2] : (new (x: { a: U; b: V; }) => U[])[] +>r15a : (new (x: { a: T; b: T; }) => T[])[] +>[r15arg, r15arg2] : (new (x: { a: T; b: T; }) => T[])[] >r15arg : new (x: { a: U; b: V; }) => U[] >r15arg2 : new (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : (new (x: { a: U; b: V; }) => U[])[] ->[r15arg2, r15arg] : (new (x: { a: U; b: V; }) => U[])[] +>r15b : (new (x: { a: T; b: T; }) => T[])[] +>[r15arg2, r15arg] : (new (x: { a: T; b: T; }) => T[])[] >r15arg2 : new (x: { a: T; b: T; }) => T[] >r15arg : new (x: { a: U; b: V; }) => U[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures6.errors.txt b/tests/baselines/reference/subtypingWithConstructSignatures6.errors.txt new file mode 100644 index 00000000000..34fa5ee287a --- /dev/null +++ b/tests/baselines/reference/subtypingWithConstructSignatures6.errors.txt @@ -0,0 +1,142 @@ +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6.ts(24,11): error TS2430: Interface 'I' incorrectly extends interface 'A'. + Types of property 'a' are incompatible. + Type 'new (x: T) => T[]' is not assignable to type 'new (x: T) => T[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6.ts(28,11): error TS2430: Interface 'I2' incorrectly extends interface 'A'. + Types of property 'a2' are incompatible. + Type 'new (x: T) => string[]' is not assignable to type 'new (x: T) => string[]'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6.ts(32,11): error TS2430: Interface 'I3' incorrectly extends interface 'A'. + Types of property 'a3' are incompatible. + Type 'new (x: T) => T' is not assignable to type 'new (x: T) => void'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6.ts(36,11): error TS2430: Interface 'I4' incorrectly extends interface 'A'. + Types of property 'a4' are incompatible. + Type 'new (x: T, y: U) => string' is not assignable to type 'new (x: T, y: U) => string'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6.ts(40,11): error TS2430: Interface 'I5' incorrectly extends interface 'A'. + Types of property 'a5' are incompatible. + Type 'new (x: (arg: T) => U) => T' is not assignable to type 'new (x: (arg: T) => U) => T'. + Types of parameters 'x' and 'x' are incompatible. + Types of parameters 'arg' and 'arg' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6.ts(44,11): error TS2430: Interface 'I7' incorrectly extends interface 'A'. + Types of property 'a11' are incompatible. + Type 'new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base' is not assignable to type 'new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ foo: T; }' is not assignable to type '{ foo: T; }'. Two different types with this name exist, but they are unrelated. + Types of property 'foo' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6.ts(48,11): error TS2430: Interface 'I9' incorrectly extends interface 'A'. + Types of property 'a16' are incompatible. + Type 'new (x: { a: T; b: T; }) => T[]' is not assignable to type 'new (x: { a: T; b: T; }) => T[]'. + Types of parameters 'x' and 'x' are incompatible. + Type '{ a: T; b: T; }' is not assignable to type '{ a: T; b: T; }'. Two different types with this name exist, but they are unrelated. + Types of property 'a' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + Type 'Base' is not assignable to type 'T'. + + +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignatures6.ts (7 errors) ==== + // checking subtype relations for function types as it relates to contextual signature instantiation + // same as subtypingWithConstructSignatures4 but using class type parameters instead of generic signatures + // all are errors + + class Base { foo: string; } + class Derived extends Base { bar: string; } + class Derived2 extends Derived { baz: string; } + class OtherDerived extends Base { bing: string; } + + interface A { // T + // M's + a: new (x: T) => T[]; + a2: new (x: T) => string[]; + a3: new (x: T) => void; + a4: new (x: T, y: U) => string; + a5: new (x: (arg: T) => U) => T; + a6: new (x: (arg: T) => Derived) => T; + a11: new (x: { foo: T }, y: { foo: T; bar: T }) => Base; + a15: new (x: { a: T; b: T }) => T[]; + a16: new (x: { a: T; b: T }) => T[]; + } + + // S's + interface I extends A { + ~ +!!! error TS2430: Interface 'I' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type 'new (x: T) => T[]' is not assignable to type 'new (x: T) => T[]'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a: new (x: T) => T[]; + } + + interface I2 extends A { + ~~ +!!! error TS2430: Interface 'I2' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type 'new (x: T) => string[]' is not assignable to type 'new (x: T) => string[]'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a2: new (x: T) => string[]; + } + + interface I3 extends A { + ~~ +!!! error TS2430: Interface 'I3' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a3' are incompatible. +!!! error TS2430: Type 'new (x: T) => T' is not assignable to type 'new (x: T) => void'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a3: new (x: T) => T; + } + + interface I4 extends A { + ~~ +!!! error TS2430: Interface 'I4' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type 'new (x: T, y: U) => string' is not assignable to type 'new (x: T, y: U) => string'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a4: new (x: T, y: U) => string; + } + + interface I5 extends A { + ~~ +!!! error TS2430: Interface 'I5' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type 'new (x: (arg: T) => U) => T' is not assignable to type 'new (x: (arg: T) => U) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Types of parameters 'arg' and 'arg' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a5: new (x: (arg: T) => U) => T; + } + + interface I7 extends A { + ~~ +!!! error TS2430: Interface 'I7' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a11' are incompatible. +!!! error TS2430: Type 'new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base' is not assignable to type 'new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type '{ foo: T; }' is not assignable to type '{ foo: T; }'. Two different types with this name exist, but they are unrelated. +!!! error TS2430: Types of property 'foo' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + a11: new (x: { foo: T }, y: { foo: U; bar: U }) => Base; + } + + interface I9 extends A { + ~~ +!!! error TS2430: Interface 'I9' incorrectly extends interface 'A'. +!!! error TS2430: Types of property 'a16' are incompatible. +!!! error TS2430: Type 'new (x: { a: T; b: T; }) => T[]' is not assignable to type 'new (x: { a: T; b: T; }) => T[]'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type '{ a: T; b: T; }' is not assignable to type '{ a: T; b: T; }'. Two different types with this name exist, but they are unrelated. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +!!! error TS2430: Type 'Base' is not assignable to type 'T'. + a16: new (x: { a: T; b: T }) => T[]; + } \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithConstructSignaturesWithSpecializedSignatures.errors.txt b/tests/baselines/reference/subtypingWithConstructSignaturesWithSpecializedSignatures.errors.txt index 8a885a2455f..a862124666d 100644 --- a/tests/baselines/reference/subtypingWithConstructSignaturesWithSpecializedSignatures.errors.txt +++ b/tests/baselines/reference/subtypingWithConstructSignaturesWithSpecializedSignatures.errors.txt @@ -2,9 +2,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Types of property 'a' are incompatible. Type 'new (x: string) => string' is not assignable to type '{ new (x: "a"): number; new (x: string): number; }'. Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignaturesWithSpecializedSignatures.ts(76,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. + Types of property 'a2' are incompatible. + Type 'new (x: T) => string' is not assignable to type 'new (x: T) => T'. + Type 'string' is not assignable to type 'T'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignaturesWithSpecializedSignatures.ts (1 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignaturesWithSpecializedSignatures.ts (2 errors) ==== // same as subtypingWithCallSignatures but with additional specialized signatures that should not affect the results module CallSignature { @@ -86,6 +90,11 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW // S's interface I3 extends Base2 { + ~~ +!!! error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type 'new (x: T) => string' is not assignable to type 'new (x: T) => T'. +!!! error TS2430: Type 'string' is not assignable to type 'T'. // N's a2: new (x: T) => string; // error because base returns non-void; } diff --git a/tests/baselines/reference/subtypingWithGenericCallSignaturesWithOptionalParameters.errors.txt b/tests/baselines/reference/subtypingWithGenericCallSignaturesWithOptionalParameters.errors.txt index e8f50236cba..1447c4d3105 100644 --- a/tests/baselines/reference/subtypingWithGenericCallSignaturesWithOptionalParameters.errors.txt +++ b/tests/baselines/reference/subtypingWithGenericCallSignaturesWithOptionalParameters.errors.txt @@ -4,12 +4,86 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(50,15): error TS2430: Interface 'I10' incorrectly extends interface 'Base'. Types of property 'a3' are incompatible. Type '(x: T, y: T) => T' is not assignable to type '(x: T) => T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(100,15): error TS2430: Interface 'I1' incorrectly extends interface 'Base2'. + Types of property 'a' are incompatible. + Type '() => T' is not assignable to type '() => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(104,15): error TS2430: Interface 'I2' incorrectly extends interface 'Base2'. + Types of property 'a' are incompatible. + Type '(x?: T) => T' is not assignable to type '() => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(108,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. Types of property 'a' are incompatible. Type '(x: T) => T' is not assignable to type '() => T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(113,15): error TS2430: Interface 'I4' incorrectly extends interface 'Base2'. + Types of property 'a2' are incompatible. + Type '() => T' is not assignable to type '(x?: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(117,15): error TS2430: Interface 'I5' incorrectly extends interface 'Base2'. + Types of property 'a2' are incompatible. + Type '(x?: T) => T' is not assignable to type '(x?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(121,15): error TS2430: Interface 'I6' incorrectly extends interface 'Base2'. + Types of property 'a2' are incompatible. + Type '(x: T) => T' is not assignable to type '(x?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(126,15): error TS2430: Interface 'I7' incorrectly extends interface 'Base2'. + Types of property 'a3' are incompatible. + Type '() => T' is not assignable to type '(x: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(130,15): error TS2430: Interface 'I8' incorrectly extends interface 'Base2'. + Types of property 'a3' are incompatible. + Type '(x?: T) => T' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(134,15): error TS2430: Interface 'I9' incorrectly extends interface 'Base2'. + Types of property 'a3' are incompatible. + Type '(x: T) => T' is not assignable to type '(x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(138,15): error TS2430: Interface 'I10' incorrectly extends interface 'Base2'. Types of property 'a3' are incompatible. Type '(x: T, y: T) => T' is not assignable to type '(x: T) => T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(143,15): error TS2430: Interface 'I11' incorrectly extends interface 'Base2'. + Types of property 'a4' are incompatible. + Type '() => T' is not assignable to type '(x: T, y?: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(147,15): error TS2430: Interface 'I12' incorrectly extends interface 'Base2'. + Types of property 'a4' are incompatible. + Type '(x?: T, y?: T) => T' is not assignable to type '(x: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(151,15): error TS2430: Interface 'I13' incorrectly extends interface 'Base2'. + Types of property 'a4' are incompatible. + Type '(x: T) => T' is not assignable to type '(x: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(155,15): error TS2430: Interface 'I14' incorrectly extends interface 'Base2'. + Types of property 'a4' are incompatible. + Type '(x: T, y: T) => T' is not assignable to type '(x: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(160,15): error TS2430: Interface 'I15' incorrectly extends interface 'Base2'. + Types of property 'a5' are incompatible. + Type '() => T' is not assignable to type '(x?: T, y?: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(164,15): error TS2430: Interface 'I16' incorrectly extends interface 'Base2'. + Types of property 'a5' are incompatible. + Type '(x?: T, y?: T) => T' is not assignable to type '(x?: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(168,15): error TS2430: Interface 'I17' incorrectly extends interface 'Base2'. + Types of property 'a5' are incompatible. + Type '(x: T) => T' is not assignable to type '(x?: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(172,15): error TS2430: Interface 'I18' incorrectly extends interface 'Base2'. + Types of property 'a5' are incompatible. + Type '(x: T, y: T) => T' is not assignable to type '(x?: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts(196,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. Types of property 'a' are incompatible. Type '(x: T) => T' is not assignable to type '() => T'. @@ -18,7 +92,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Type '(x: T, y: T) => T' is not assignable to type '(x: T) => T'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts (6 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters.ts (22 errors) ==== // call signatures in derived types must have the same or fewer optional parameters as the base type module ClassTypeParam { @@ -127,10 +201,20 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW } interface I1 extends Base2 { + ~~ +!!! error TS2430: Interface 'I1' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type '() => T' is not assignable to type '() => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a: () => T; } interface I2 extends Base2 { + ~~ +!!! error TS2430: Interface 'I2' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type '(x?: T) => T' is not assignable to type '() => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a: (x?: T) => T; } @@ -144,27 +228,61 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface I4 extends Base2 { + ~~ +!!! error TS2430: Interface 'I4' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type '() => T' is not assignable to type '(x?: T) => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a2: () => T; } interface I5 extends Base2 { + ~~ +!!! error TS2430: Interface 'I5' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type '(x?: T) => T' is not assignable to type '(x?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a2: (x?: T) => T } interface I6 extends Base2 { + ~~ +!!! error TS2430: Interface 'I6' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type '(x: T) => T' is not assignable to type '(x?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a2: (x: T) => T; } interface I7 extends Base2 { + ~~ +!!! error TS2430: Interface 'I7' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a3' are incompatible. +!!! error TS2430: Type '() => T' is not assignable to type '(x: T) => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a3: () => T; } interface I8 extends Base2 { + ~~ +!!! error TS2430: Interface 'I8' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a3' are incompatible. +!!! error TS2430: Type '(x?: T) => T' is not assignable to type '(x: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a3: (x?: T) => T; } interface I9 extends Base2 { + ~~ +!!! error TS2430: Interface 'I9' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a3' are incompatible. +!!! error TS2430: Type '(x: T) => T' is not assignable to type '(x: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a3: (x: T) => T; } @@ -178,35 +296,81 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface I11 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I11' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type '() => T' is not assignable to type '(x: T, y?: T) => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a4: () => T; } interface I12 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I12' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type '(x?: T, y?: T) => T' is not assignable to type '(x: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a4: (x?: T, y?: T) => T; } interface I13 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I13' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type '(x: T) => T' is not assignable to type '(x: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a4: (x: T) => T; } interface I14 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I14' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type '(x: T, y: T) => T' is not assignable to type '(x: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a4: (x: T, y: T) => T; } interface I15 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I15' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type '() => T' is not assignable to type '(x?: T, y?: T) => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a5: () => T; } interface I16 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I16' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type '(x?: T, y?: T) => T' is not assignable to type '(x?: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a5: (x?: T, y?: T) => T; } interface I17 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I17' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type '(x: T) => T' is not assignable to type '(x?: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a5: (x: T) => T; } interface I18 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I18' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type '(x: T, y: T) => T' is not assignable to type '(x?: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a5: (x: T, y: T) => T; } } diff --git a/tests/baselines/reference/subtypingWithGenericConstructSignaturesWithOptionalParameters.errors.txt b/tests/baselines/reference/subtypingWithGenericConstructSignaturesWithOptionalParameters.errors.txt index 27066058238..28682b99a66 100644 --- a/tests/baselines/reference/subtypingWithGenericConstructSignaturesWithOptionalParameters.errors.txt +++ b/tests/baselines/reference/subtypingWithGenericConstructSignaturesWithOptionalParameters.errors.txt @@ -4,12 +4,86 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(50,15): error TS2430: Interface 'I10' incorrectly extends interface 'Base'. Types of property 'a3' are incompatible. Type 'new (x: T, y: T) => T' is not assignable to type 'new (x: T) => T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(100,15): error TS2430: Interface 'I1' incorrectly extends interface 'Base2'. + Types of property 'a' are incompatible. + Type 'new () => T' is not assignable to type 'new () => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(104,15): error TS2430: Interface 'I2' incorrectly extends interface 'Base2'. + Types of property 'a' are incompatible. + Type 'new (x?: T) => T' is not assignable to type 'new () => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(108,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. Types of property 'a' are incompatible. Type 'new (x: T) => T' is not assignable to type 'new () => T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(113,15): error TS2430: Interface 'I4' incorrectly extends interface 'Base2'. + Types of property 'a2' are incompatible. + Type 'new () => T' is not assignable to type 'new (x?: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(117,15): error TS2430: Interface 'I5' incorrectly extends interface 'Base2'. + Types of property 'a2' are incompatible. + Type 'new (x?: T) => T' is not assignable to type 'new (x?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(121,15): error TS2430: Interface 'I6' incorrectly extends interface 'Base2'. + Types of property 'a2' are incompatible. + Type 'new (x: T) => T' is not assignable to type 'new (x?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(126,15): error TS2430: Interface 'I7' incorrectly extends interface 'Base2'. + Types of property 'a3' are incompatible. + Type 'new () => T' is not assignable to type 'new (x: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(130,15): error TS2430: Interface 'I8' incorrectly extends interface 'Base2'. + Types of property 'a3' are incompatible. + Type 'new (x?: T) => T' is not assignable to type 'new (x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(134,15): error TS2430: Interface 'I9' incorrectly extends interface 'Base2'. + Types of property 'a3' are incompatible. + Type 'new (x: T) => T' is not assignable to type 'new (x: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(138,15): error TS2430: Interface 'I10' incorrectly extends interface 'Base2'. Types of property 'a3' are incompatible. Type 'new (x: T, y: T) => T' is not assignable to type 'new (x: T) => T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(143,15): error TS2430: Interface 'I11' incorrectly extends interface 'Base2'. + Types of property 'a4' are incompatible. + Type 'new () => T' is not assignable to type 'new (x: T, y?: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(147,15): error TS2430: Interface 'I12' incorrectly extends interface 'Base2'. + Types of property 'a4' are incompatible. + Type 'new (x?: T, y?: T) => T' is not assignable to type 'new (x: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(151,15): error TS2430: Interface 'I13' incorrectly extends interface 'Base2'. + Types of property 'a4' are incompatible. + Type 'new (x: T) => T' is not assignable to type 'new (x: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(155,15): error TS2430: Interface 'I14' incorrectly extends interface 'Base2'. + Types of property 'a4' are incompatible. + Type 'new (x: T, y: T) => T' is not assignable to type 'new (x: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(160,15): error TS2430: Interface 'I15' incorrectly extends interface 'Base2'. + Types of property 'a5' are incompatible. + Type 'new () => T' is not assignable to type 'new (x?: T, y?: T) => T'. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(164,15): error TS2430: Interface 'I16' incorrectly extends interface 'Base2'. + Types of property 'a5' are incompatible. + Type 'new (x?: T, y?: T) => T' is not assignable to type 'new (x?: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(168,15): error TS2430: Interface 'I17' incorrectly extends interface 'Base2'. + Types of property 'a5' are incompatible. + Type 'new (x: T) => T' is not assignable to type 'new (x?: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(172,15): error TS2430: Interface 'I18' incorrectly extends interface 'Base2'. + Types of property 'a5' are incompatible. + Type 'new (x: T, y: T) => T' is not assignable to type 'new (x?: T, y?: T) => T'. + Types of parameters 'x' and 'x' are incompatible. + Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts(196,15): error TS2430: Interface 'I3' incorrectly extends interface 'Base2'. Types of property 'a' are incompatible. Type 'new (x: T) => T' is not assignable to type 'new () => T'. @@ -18,7 +92,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW Type 'new (x: T, y: T) => T' is not assignable to type 'new (x: T) => T'. -==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts (6 errors) ==== +==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters.ts (22 errors) ==== // call signatures in derived types must have the same or fewer optional parameters as the base type module ClassTypeParam { @@ -127,10 +201,20 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW } interface I1 extends Base2 { + ~~ +!!! error TS2430: Interface 'I1' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type 'new () => T' is not assignable to type 'new () => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a: new () => T; } interface I2 extends Base2 { + ~~ +!!! error TS2430: Interface 'I2' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a' are incompatible. +!!! error TS2430: Type 'new (x?: T) => T' is not assignable to type 'new () => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a: new (x?: T) => T; } @@ -144,27 +228,61 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface I4 extends Base2 { + ~~ +!!! error TS2430: Interface 'I4' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type 'new () => T' is not assignable to type 'new (x?: T) => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a2: new () => T; } interface I5 extends Base2 { + ~~ +!!! error TS2430: Interface 'I5' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type 'new (x?: T) => T' is not assignable to type 'new (x?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a2: new (x?: T) => T } interface I6 extends Base2 { + ~~ +!!! error TS2430: Interface 'I6' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a2' are incompatible. +!!! error TS2430: Type 'new (x: T) => T' is not assignable to type 'new (x?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a2: new (x: T) => T; } interface I7 extends Base2 { + ~~ +!!! error TS2430: Interface 'I7' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a3' are incompatible. +!!! error TS2430: Type 'new () => T' is not assignable to type 'new (x: T) => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a3: new () => T; } interface I8 extends Base2 { + ~~ +!!! error TS2430: Interface 'I8' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a3' are incompatible. +!!! error TS2430: Type 'new (x?: T) => T' is not assignable to type 'new (x: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a3: new (x?: T) => T; } interface I9 extends Base2 { + ~~ +!!! error TS2430: Interface 'I9' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a3' are incompatible. +!!! error TS2430: Type 'new (x: T) => T' is not assignable to type 'new (x: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a3: new (x: T) => T; } @@ -178,35 +296,81 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface I11 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I11' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type 'new () => T' is not assignable to type 'new (x: T, y?: T) => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a4: new () => T; } interface I12 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I12' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type 'new (x?: T, y?: T) => T' is not assignable to type 'new (x: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a4: new (x?: T, y?: T) => T; } interface I13 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I13' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type 'new (x: T) => T' is not assignable to type 'new (x: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a4: new (x: T) => T; } interface I14 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I14' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a4' are incompatible. +!!! error TS2430: Type 'new (x: T, y: T) => T' is not assignable to type 'new (x: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a4: new (x: T, y: T) => T; } interface I15 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I15' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type 'new () => T' is not assignable to type 'new (x?: T, y?: T) => T'. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a5: new () => T; } interface I16 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I16' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type 'new (x?: T, y?: T) => T' is not assignable to type 'new (x?: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a5: new (x?: T, y?: T) => T; } interface I17 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I17' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type 'new (x: T) => T' is not assignable to type 'new (x?: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a5: new (x: T) => T; } interface I18 extends Base2 { + ~~~ +!!! error TS2430: Interface 'I18' incorrectly extends interface 'Base2'. +!!! error TS2430: Types of property 'a5' are incompatible. +!!! error TS2430: Type 'new (x: T, y: T) => T' is not assignable to type 'new (x?: T, y?: T) => T'. +!!! error TS2430: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2430: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. a5: new (x: T, y: T) => T; } } diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution1.js b/tests/baselines/reference/tsxSpreadAttributesResolution1.js index f8c3cfbb594..7d83e9bd390 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution1.js +++ b/tests/baselines/reference/tsxSpreadAttributesResolution1.js @@ -7,11 +7,12 @@ class Poisoned extends React.Component<{}, {}> { } } -const obj: Object = {}; +const obj = {}; // OK let p = ; -let y = ; +let y = ; + //// [file.jsx] "use strict"; diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution1.symbols b/tests/baselines/reference/tsxSpreadAttributesResolution1.symbols index 82a4e5cc822..9b3f535f309 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution1.symbols +++ b/tests/baselines/reference/tsxSpreadAttributesResolution1.symbols @@ -17,9 +17,8 @@ class Poisoned extends React.Component<{}, {}> { } } -const obj: Object = {}; +const obj = {}; >obj : Symbol(obj, Decl(file.tsx, 8, 5)) ->Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) // OK let p = ; diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution1.types b/tests/baselines/reference/tsxSpreadAttributesResolution1.types index f8f1cb8d15a..26f83c74001 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution1.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution1.types @@ -18,9 +18,8 @@ class Poisoned extends React.Component<{}, {}> { } } -const obj: Object = {}; ->obj : Object ->Object : Object +const obj = {}; +>obj : {} >{} : {} // OK @@ -28,7 +27,7 @@ let p = ; >p : JSX.Element > : JSX.Element >Poisoned : typeof Poisoned ->obj : Object +>obj : {} let y = ; >y : JSX.Element diff --git a/tests/baselines/reference/typeFromParamTagForFunction.symbols b/tests/baselines/reference/typeFromParamTagForFunction.symbols new file mode 100644 index 00000000000..0df0dfdc206 --- /dev/null +++ b/tests/baselines/reference/typeFromParamTagForFunction.symbols @@ -0,0 +1,184 @@ +=== tests/cases/conformance/salsa/node.d.ts === +declare function require(id: string): any; +>require : Symbol(require, Decl(node.d.ts, 0, 0)) +>id : Symbol(id, Decl(node.d.ts, 0, 25)) + +declare var module: any, exports: any; +>module : Symbol(module, Decl(node.d.ts, 1, 11)) +>exports : Symbol(exports, Decl(node.d.ts, 1, 24)) + +=== tests/cases/conformance/salsa/a-ext.js === +exports.A = function () { +>exports : Symbol(A, Decl(a-ext.js, 0, 0)) +>A : Symbol(A, Decl(a-ext.js, 0, 0)) + + this.x = 1; +>x : Symbol((Anonymous function).x, Decl(a-ext.js, 0, 25)) + +}; + +=== tests/cases/conformance/salsa/a.js === +const { A } = require("./a-ext"); +>A : Symbol(A, Decl(a.js, 0, 7)) +>require : Symbol(require, Decl(node.d.ts, 0, 0)) +>"./a-ext" : Symbol("tests/cases/conformance/salsa/a-ext", Decl(a-ext.js, 0, 0)) + +/** @param {A} p */ +function a(p) { p.x; } +>a : Symbol(a, Decl(a.js, 0, 33)) +>p : Symbol(p, Decl(a.js, 3, 11)) +>p.x : Symbol((Anonymous function).x, Decl(a-ext.js, 0, 25)) +>p : Symbol(p, Decl(a.js, 3, 11)) +>x : Symbol((Anonymous function).x, Decl(a-ext.js, 0, 25)) + +=== tests/cases/conformance/salsa/b-ext.js === +exports.B = class { +>exports : Symbol(B, Decl(b-ext.js, 0, 0)) +>B : Symbol(B, Decl(b-ext.js, 0, 0)) + + constructor() { + this.x = 1; +>this.x : Symbol((Anonymous class).x, Decl(b-ext.js, 1, 19)) +>this : Symbol((Anonymous class), Decl(b-ext.js, 0, 11)) +>x : Symbol((Anonymous class).x, Decl(b-ext.js, 1, 19)) + } +}; + +=== tests/cases/conformance/salsa/b.js === +const { B } = require("./b-ext"); +>B : Symbol(B, Decl(b.js, 0, 7)) +>require : Symbol(require, Decl(node.d.ts, 0, 0)) +>"./b-ext" : Symbol("tests/cases/conformance/salsa/b-ext", Decl(b-ext.js, 0, 0)) + +/** @param {B} p */ +function b(p) { p.x; } +>b : Symbol(b, Decl(b.js, 0, 33)) +>p : Symbol(p, Decl(b.js, 3, 11)) +>p.x : Symbol((Anonymous class).x, Decl(b-ext.js, 1, 19)) +>p : Symbol(p, Decl(b.js, 3, 11)) +>x : Symbol((Anonymous class).x, Decl(b-ext.js, 1, 19)) + +=== tests/cases/conformance/salsa/c-ext.js === +export function C() { +>C : Symbol(C, Decl(c-ext.js, 0, 0)) + + this.x = 1; +>x : Symbol(C.x, Decl(c-ext.js, 0, 21)) +} + +=== tests/cases/conformance/salsa/c.js === +const { C } = require("./c-ext"); +>C : Symbol(C, Decl(c.js, 0, 7)) +>require : Symbol(require, Decl(node.d.ts, 0, 0)) +>"./c-ext" : Symbol("tests/cases/conformance/salsa/c-ext", Decl(c-ext.js, 0, 0)) + +/** @param {C} p */ +function c(p) { p.x; } +>c : Symbol(c, Decl(c.js, 0, 33)) +>p : Symbol(p, Decl(c.js, 3, 11)) +>p.x : Symbol(C.x, Decl(c-ext.js, 0, 21)) +>p : Symbol(p, Decl(c.js, 3, 11)) +>x : Symbol(C.x, Decl(c-ext.js, 0, 21)) + +=== tests/cases/conformance/salsa/d-ext.js === +export var D = function() { +>D : Symbol(D, Decl(d-ext.js, 0, 10)) + + this.x = 1; +>x : Symbol(D.x, Decl(d-ext.js, 0, 27)) + +}; + +=== tests/cases/conformance/salsa/d.js === +const { D } = require("./d-ext"); +>D : Symbol(D, Decl(d.js, 0, 7)) +>require : Symbol(require, Decl(node.d.ts, 0, 0)) +>"./d-ext" : Symbol("tests/cases/conformance/salsa/d-ext", Decl(d-ext.js, 0, 0)) + +/** @param {D} p */ +function d(p) { p.x; } +>d : Symbol(d, Decl(d.js, 0, 33)) +>p : Symbol(p, Decl(d.js, 3, 11)) +>p.x : Symbol(D.x, Decl(d-ext.js, 0, 27)) +>p : Symbol(p, Decl(d.js, 3, 11)) +>x : Symbol(D.x, Decl(d-ext.js, 0, 27)) + +=== tests/cases/conformance/salsa/e-ext.js === +export class E { +>E : Symbol(E, Decl(e-ext.js, 0, 0)) + + constructor() { + this.x = 1; +>this.x : Symbol(E.x, Decl(e-ext.js, 1, 19)) +>this : Symbol(E, Decl(e-ext.js, 0, 0)) +>x : Symbol(E.x, Decl(e-ext.js, 1, 19)) + } +} + +=== tests/cases/conformance/salsa/e.js === +const { E } = require("./e-ext"); +>E : Symbol(E, Decl(e.js, 0, 7)) +>require : Symbol(require, Decl(node.d.ts, 0, 0)) +>"./e-ext" : Symbol("tests/cases/conformance/salsa/e-ext", Decl(e-ext.js, 0, 0)) + +/** @param {E} p */ +function e(p) { p.x; } +>e : Symbol(e, Decl(e.js, 0, 33)) +>p : Symbol(p, Decl(e.js, 3, 11)) +>p.x : Symbol(E.x, Decl(e-ext.js, 1, 19)) +>p : Symbol(p, Decl(e.js, 3, 11)) +>x : Symbol(E.x, Decl(e-ext.js, 1, 19)) + +=== tests/cases/conformance/salsa/f.js === +var F = function () { +>F : Symbol(F, Decl(f.js, 0, 3)) + + this.x = 1; +>x : Symbol(F.x, Decl(f.js, 0, 21)) + +}; + +/** @param {F} p */ +function f(p) { p.x; } +>f : Symbol(f, Decl(f.js, 2, 2)) +>p : Symbol(p, Decl(f.js, 5, 11)) +>p.x : Symbol(F.x, Decl(f.js, 0, 21)) +>p : Symbol(p, Decl(f.js, 5, 11)) +>x : Symbol(F.x, Decl(f.js, 0, 21)) + +=== tests/cases/conformance/salsa/g.js === +function G() { +>G : Symbol(G, Decl(g.js, 0, 0)) + + this.x = 1; +>x : Symbol(G.x, Decl(g.js, 0, 14)) +} + +/** @param {G} p */ +function g(p) { p.x; } +>g : Symbol(g, Decl(g.js, 2, 1)) +>p : Symbol(p, Decl(g.js, 5, 11)) +>p.x : Symbol(G.x, Decl(g.js, 0, 14)) +>p : Symbol(p, Decl(g.js, 5, 11)) +>x : Symbol(G.x, Decl(g.js, 0, 14)) + +=== tests/cases/conformance/salsa/h.js === +class H { +>H : Symbol(H, Decl(h.js, 0, 0)) + + constructor() { + this.x = 1; +>this.x : Symbol(H.x, Decl(h.js, 1, 19)) +>this : Symbol(H, Decl(h.js, 0, 0)) +>x : Symbol(H.x, Decl(h.js, 1, 19)) + } +} + +/** @param {H} p */ +function h(p) { p.x; } +>h : Symbol(h, Decl(h.js, 4, 1)) +>p : Symbol(p, Decl(h.js, 7, 11)) +>p.x : Symbol(H.x, Decl(h.js, 1, 19)) +>p : Symbol(p, Decl(h.js, 7, 11)) +>x : Symbol(H.x, Decl(h.js, 1, 19)) + diff --git a/tests/baselines/reference/typeFromParamTagForFunction.types b/tests/baselines/reference/typeFromParamTagForFunction.types new file mode 100644 index 00000000000..c1e16ddb33d --- /dev/null +++ b/tests/baselines/reference/typeFromParamTagForFunction.types @@ -0,0 +1,223 @@ +=== tests/cases/conformance/salsa/node.d.ts === +declare function require(id: string): any; +>require : (id: string) => any +>id : string + +declare var module: any, exports: any; +>module : any +>exports : any + +=== tests/cases/conformance/salsa/a-ext.js === +exports.A = function () { +>exports.A = function () { this.x = 1;} : () => void +>exports.A : any +>exports : any +>A : any +>function () { this.x = 1;} : () => void + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : any +>x : any +>1 : 1 + +}; + +=== tests/cases/conformance/salsa/a.js === +const { A } = require("./a-ext"); +>A : () => void +>require("./a-ext") : typeof "tests/cases/conformance/salsa/a-ext" +>require : (id: string) => any +>"./a-ext" : "./a-ext" + +/** @param {A} p */ +function a(p) { p.x; } +>a : (p: { x: number; }) => void +>p : { x: number; } +>p.x : number +>p : { x: number; } +>x : number + +=== tests/cases/conformance/salsa/b-ext.js === +exports.B = class { +>exports.B = class { constructor() { this.x = 1; }} : typeof (Anonymous class) +>exports.B : any +>exports : any +>B : any +>class { constructor() { this.x = 1; }} : typeof (Anonymous class) + + constructor() { + this.x = 1; +>this.x = 1 : 1 +>this.x : number +>this : this +>x : number +>1 : 1 + } +}; + +=== tests/cases/conformance/salsa/b.js === +const { B } = require("./b-ext"); +>B : typeof (Anonymous class) +>require("./b-ext") : typeof "tests/cases/conformance/salsa/b-ext" +>require : (id: string) => any +>"./b-ext" : "./b-ext" + +/** @param {B} p */ +function b(p) { p.x; } +>b : (p: (Anonymous class)) => void +>p : (Anonymous class) +>p.x : number +>p : (Anonymous class) +>x : number + +=== tests/cases/conformance/salsa/c-ext.js === +export function C() { +>C : () => void + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : any +>x : any +>1 : 1 +} + +=== tests/cases/conformance/salsa/c.js === +const { C } = require("./c-ext"); +>C : () => void +>require("./c-ext") : typeof "tests/cases/conformance/salsa/c-ext" +>require : (id: string) => any +>"./c-ext" : "./c-ext" + +/** @param {C} p */ +function c(p) { p.x; } +>c : (p: { x: number; }) => void +>p : { x: number; } +>p.x : number +>p : { x: number; } +>x : number + +=== tests/cases/conformance/salsa/d-ext.js === +export var D = function() { +>D : () => void +>function() { this.x = 1;} : () => void + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : any +>x : any +>1 : 1 + +}; + +=== tests/cases/conformance/salsa/d.js === +const { D } = require("./d-ext"); +>D : () => void +>require("./d-ext") : typeof "tests/cases/conformance/salsa/d-ext" +>require : (id: string) => any +>"./d-ext" : "./d-ext" + +/** @param {D} p */ +function d(p) { p.x; } +>d : (p: { x: number; }) => void +>p : { x: number; } +>p.x : number +>p : { x: number; } +>x : number + +=== tests/cases/conformance/salsa/e-ext.js === +export class E { +>E : E + + constructor() { + this.x = 1; +>this.x = 1 : 1 +>this.x : number +>this : this +>x : number +>1 : 1 + } +} + +=== tests/cases/conformance/salsa/e.js === +const { E } = require("./e-ext"); +>E : typeof E +>require("./e-ext") : typeof "tests/cases/conformance/salsa/e-ext" +>require : (id: string) => any +>"./e-ext" : "./e-ext" + +/** @param {E} p */ +function e(p) { p.x; } +>e : (p: E) => void +>p : E +>p.x : number +>p : E +>x : number + +=== tests/cases/conformance/salsa/f.js === +var F = function () { +>F : () => void +>function () { this.x = 1;} : () => void + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : any +>x : any +>1 : 1 + +}; + +/** @param {F} p */ +function f(p) { p.x; } +>f : (p: { x: number; }) => void +>p : { x: number; } +>p.x : number +>p : { x: number; } +>x : number + +=== tests/cases/conformance/salsa/g.js === +function G() { +>G : () => void + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : any +>x : any +>1 : 1 +} + +/** @param {G} p */ +function g(p) { p.x; } +>g : (p: { x: number; }) => void +>p : { x: number; } +>p.x : number +>p : { x: number; } +>x : number + +=== tests/cases/conformance/salsa/h.js === +class H { +>H : H + + constructor() { + this.x = 1; +>this.x = 1 : 1 +>this.x : number +>this : this +>x : number +>1 : 1 + } +} + +/** @param {H} p */ +function h(p) { p.x; } +>h : (p: H) => void +>p : H +>p.x : number +>p : H +>x : number + diff --git a/tests/baselines/reference/typeParameterConstrainedToOuterTypeParameter.errors.txt b/tests/baselines/reference/typeParameterConstrainedToOuterTypeParameter.errors.txt new file mode 100644 index 00000000000..926ad4b3bff --- /dev/null +++ b/tests/baselines/reference/typeParameterConstrainedToOuterTypeParameter.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/typeParameterConstrainedToOuterTypeParameter.ts(10,5): error TS2322: Type 'A' is not assignable to type 'B'. + Types of parameters 'x' and 'x' are incompatible. + Type 'U' is not assignable to type 'string[]'. + Type 'string' is not assignable to type 'string[]'. + + +==== tests/cases/compiler/typeParameterConstrainedToOuterTypeParameter.ts (1 errors) ==== + interface A { + (x: U[]) + } + + interface B { + (x: U) + } + + var a: A + var b: B = a; // assignment should be legal (both U's get instantiated to any for comparison) + ~ +!!! error TS2322: Type 'A' is not assignable to type 'B'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'U' is not assignable to type 'string[]'. +!!! error TS2322: Type 'string' is not assignable to type 'string[]'. \ No newline at end of file diff --git a/tests/baselines/reference/underscoreTest1.errors.txt b/tests/baselines/reference/underscoreTest1.errors.txt new file mode 100644 index 00000000000..ca8df792231 --- /dev/null +++ b/tests/baselines/reference/underscoreTest1.errors.txt @@ -0,0 +1,908 @@ +tests/cases/compiler/underscoreTest1_underscoreTests.ts(26,7): error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type 'Dictionary<{}>'. + Index signature is missing in type '(string | number | boolean)[]'. + + +==== tests/cases/compiler/underscoreTest1_underscoreTests.ts (1 errors) ==== + /// + + declare var $; + declare function alert(x: string): void; + + _.each([1, 2, 3], (num) => alert(num.toString())); + _.each({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => alert(value.toString())); + + _.map([1, 2, 3], (num) => num * 3); + _.map({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => value * 3); + + var sum = _.reduce([1, 2, 3], (memo, num) => memo + num, 0); + + var list = [[0, 1], [2, 3], [4, 5]]; + var flat = _.reduceRight(list, (a, b) => a.concat(b), []); + + var even = _.find([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); + + var evens = _.filter([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); + + var listOfPlays = [{ title: "Cymbeline", author: "Shakespeare", year: 1611 }, { title: "The Tempest", author: "Shakespeare", year: 1611 }, { title: "Other", author: "Not Shakespeare", year: 2012 }]; + _.where(listOfPlays, { author: "Shakespeare", year: 1611 }); + + var odds = _.reject([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); + + _.all([true, 1, null, 'yes'], _.identity); + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type 'Dictionary<{}>'. +!!! error TS2345: Index signature is missing in type '(string | number | boolean)[]'. + + _.any([null, 0, 'yes', false]); + + _.contains([1, 2, 3], 3); + + _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); + + var stooges = [{ name: 'moe', age: 40 }, { name: 'larry', age: 50 }, { name: 'curly', age: 60 }]; + _.pluck(stooges, 'name'); + + _.max(stooges, (stooge) => stooge.age); + + var numbers = [10, 5, 100, 2, 1000]; + _.min(numbers); + + _.sortBy([1, 2, 3, 4, 5, 6], (num) => Math.sin(num)); + + + // not sure how this is typechecking at all.. Math.floor(e) is number not string..? + _([1.3, 2.1, 2.4]).groupBy((e: number, i?: number, list?: number[]) => Math.floor(e)); + _.groupBy([1.3, 2.1, 2.4], (num: number) => Math.floor(num)); + _.groupBy(['one', 'two', 'three'], 'length'); + + _.countBy([1, 2, 3, 4, 5], (num) => num % 2 == 0 ? 'even' : 'odd'); + + _.shuffle([1, 2, 3, 4, 5, 6]); + + // (function(){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4); + + _.size({ one: 1, two: 2, three: 3 }); + + /////////////////////////////////////////////////////////////////////////////////////// + + _.first([5, 4, 3, 2, 1]); + _.initial([5, 4, 3, 2, 1]); + _.last([5, 4, 3, 2, 1]); + _.rest([5, 4, 3, 2, 1]); + _.compact([0, 1, false, 2, '', 3]); + + _.flatten([1, 2, 3, 4]); + _.flatten([1, [2]]); + + // typescript doesn't like the elements being different + _.flatten([1, [2], [3, [[4]]]]); + _.flatten([1, [2], [3, [[4]]]], true); + _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); + _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); + _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); + _.difference([1, 2, 3, 4, 5], [5, 2, 10]); + _.uniq([1, 2, 1, 3, 1, 4]); + _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); + _.object(['moe', 'larry', 'curly'], [30, 40, 50]); + _.object([['moe', 30], ['larry', 40], ['curly', 50]]); + _.indexOf([1, 2, 3], 2); + _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); + _.sortedIndex([10, 20, 30, 40, 50], 35); + _.range(10); + _.range(1, 11); + _.range(0, 30, 5); + _.range(0, 30, 5); + _.range(0); + + /////////////////////////////////////////////////////////////////////////////////////// + + var func = function (greeting) { return greeting + ': ' + this.name }; + // need a second var otherwise typescript thinks func signature is the above func type, + // instead of the newly returned _bind => func type. + var func2 = _.bind(func, { name: 'moe' }, 'hi'); + func2(); + + var buttonView = { + label: 'underscore', + onClick: function () { alert('clicked: ' + this.label); }, + onHover: function () { alert('hovering: ' + this.label); } + }; + _.bindAll(buttonView); + $('#underscore_button').bind('click', buttonView.onClick); + + var fibonacci = _.memoize(function (n) { + return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); + }); + + var log = _.bind((message?: string, ...rest: string[]) => { }, Date); + _.delay(log, 1000, 'logged later'); + + _.defer(function () { alert('deferred'); }); + + var updatePosition = () => alert('updating position...'); + var throttled = _.throttle(updatePosition, 100); + $(null).scroll(throttled); + + var calculateLayout = () => alert('calculating layout...'); + var lazyLayout = _.debounce(calculateLayout, 300); + $(null).resize(lazyLayout); + + var createApplication = () => alert('creating application...'); + var initialize = _.once(createApplication); + initialize(); + initialize(); + + var notes: any[]; + var render = () => alert("rendering..."); + var renderNotes = _.after(notes.length, render); + _.each(notes, (note) => note.asyncSave({ success: renderNotes })); + + var hello = function (name) { return "hello: " + name; }; + hello = _.wrap(hello, (func, arg) => { return "before, " + func(arg) + ", after"; }); + hello("moe"); + + var greet = function (name) { return "hi: " + name; }; + var exclaim = function (statement) { return statement + "!"; }; + var welcome = _.compose(exclaim, greet); + welcome('moe'); + + /////////////////////////////////////////////////////////////////////////////////////// + + _.keys({ one: 1, two: 2, three: 3 }); + _.values({ one: 1, two: 2, three: 3 }); + _.pairs({ one: 1, two: 2, three: 3 }); + _.invert({ Moe: "Moses", Larry: "Louis", Curly: "Jerome" }); + _.functions(_); + _.extend({ name: 'moe' }, { age: 50 }); + _.pick({ name: 'moe', age: 50, userid: 'moe1' }, 'name', 'age'); + _.omit({ name: 'moe', age: 50, userid: 'moe1' }, 'userid'); + + var iceCream = { flavor: "chocolate" }; + _.defaults(iceCream, { flavor: "vanilla", sprinkles: "lots" }); + + _.clone({ name: 'moe' }); + + _.chain([1, 2, 3, 200]) + .filter(function (num) { return num % 2 == 0; }) + .tap(alert) + .map(function (num) { return num * num }) + .value(); + + _.has({ a: 1, b: 2, c: 3 }, "b"); + + var moe = { name: 'moe', luckyNumbers: [13, 27, 34] }; + var clone = { name: 'moe', luckyNumbers: [13, 27, 34] }; + moe == clone; + _.isEqual(moe, clone); + + _.isEmpty([1, 2, 3]); + _.isEmpty({}); + + _.isElement($('body')[0]); + + (function () { return _.isArray(arguments); })(); + _.isArray([1, 2, 3]); + + _.isObject({}); + _.isObject(1); + + + // (() => { return _.isArguments(arguments); })(1, 2, 3); + _.isArguments([1, 2, 3]); + + _.isFunction(alert); + + _.isString("moe"); + + _.isNumber(8.4 * 5); + + _.isFinite(-101); + + _.isFinite(-Infinity); + + _.isBoolean(null); + + _.isDate(new Date()); + + _.isRegExp(/moe/); + + _.isNaN(NaN); + isNaN(undefined); + _.isNaN(undefined); + + _.isNull(null); + _.isNull(undefined); + + _.isUndefined((null).missingVariable); + + /////////////////////////////////////////////////////////////////////////////////////// + + var underscore = _.noConflict(); + + var moe2 = { name: 'moe' }; + moe2 === _.identity(moe); + + var genie; + + _.times(3, function (n) { genie.grantWishNumber(n); }); + + _.random(0, 100); + + _.mixin({ + capitalize: function (string) { + return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase(); + } + }); + (_("fabio")).capitalize(); + + _.uniqueId('contact_'); + + _.escape('Curly, Larry & Moe'); + + var object = { cheese: 'crumpets', stuff: function () { return 'nonsense'; } }; + _.result(object, 'cheese'); + + _.result(object, 'stuff'); + + var compiled = _.template("hello: <%= name %>"); + compiled({ name: 'moe' }); + var list2 = "<% _.each(people, function(name) { %>
  • <%= name %>
  • <% }); %>"; + _.template(list2, { people: ['moe', 'curly', 'larry'] }); + var template = _.template("<%- value %>"); + template({ value: '