From 5999a521f6e852de92681acf8c91c01f102edab6 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Sat, 31 Dec 2016 19:12:57 -0800 Subject: [PATCH 001/138] Support for an external exportStar helper --- src/compiler/checker.ts | 8 ++- src/compiler/factory.ts | 52 ++++++++++++------- src/compiler/transformers/module/module.ts | 24 ++++----- src/compiler/types.ts | 3 +- tests/baselines/reference/importHelpersAmd.js | 8 ++- .../reference/importHelpersAmd.symbols | 19 ++++++- .../reference/importHelpersAmd.types | 17 ++++++ .../importHelpersInAmbientContext.js | 4 +- .../importHelpersInAmbientContext.symbols | 16 ++++++ .../importHelpersInAmbientContext.types | 16 ++++++ .../importHelpersNoHelpers.errors.txt | 21 +++++--- .../reference/importHelpersNoHelpers.js | 8 +++ .../reference/importHelpersSystem.js | 12 +++++ .../reference/importHelpersSystem.symbols | 3 +- .../reference/importHelpersSystem.types | 1 + tests/cases/compiler/importHelpersAmd.ts | 4 ++ .../compiler/importHelpersInAmbientContext.ts | 3 ++ .../cases/compiler/importHelpersNoHelpers.ts | 4 ++ tests/cases/compiler/importHelpersSystem.ts | 1 + 19 files changed, 178 insertions(+), 46 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 33b3505661a..2900932bc00 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19160,6 +19160,10 @@ namespace ts { if (moduleSymbol && hasExportAssignmentSymbol(moduleSymbol)) { error(node.moduleSpecifier, Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol)); } + + if (modulekind !== ModuleKind.System && modulekind !== ModuleKind.ES2015) { + checkExternalEmitHelpers(node, ExternalEmitHelpers.ExportStar); + } } } } @@ -20788,7 +20792,7 @@ namespace ts { function checkExternalEmitHelpers(location: Node, helpers: ExternalEmitHelpers) { if ((requestedExternalEmitHelpers & helpers) !== helpers && compilerOptions.importHelpers) { const sourceFile = getSourceFileOfNode(location); - if (isEffectiveExternalModule(sourceFile, compilerOptions)) { + if (!isDeclarationFile(sourceFile) && isEffectiveExternalModule(sourceFile, compilerOptions)) { const helpersModule = resolveHelpersModule(sourceFile, location); if (helpersModule !== unknownSymbol) { const uncheckedHelpers = helpers & ~requestedExternalEmitHelpers; @@ -20817,6 +20821,8 @@ namespace ts { case ExternalEmitHelpers.Param: return "__param"; case ExternalEmitHelpers.Awaiter: return "__awaiter"; case ExternalEmitHelpers.Generator: return "__generator"; + case ExternalEmitHelpers.ExportStar: return "__exportStar"; + default: Debug.fail("Unrecognized helper"); } } diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index ac1f52a991f..033d694ade2 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2808,25 +2808,37 @@ namespace ts { return emitNode && emitNode.externalHelpersModuleName; } - export function getOrCreateExternalHelpersModuleNameIfNeeded(node: SourceFile, compilerOptions: CompilerOptions) { - if (compilerOptions.importHelpers && (isExternalModule(node) || compilerOptions.isolatedModules)) { + export function getOrCreateExternalHelpersModuleNameIfNeeded(node: SourceFile, compilerOptions: CompilerOptions, hasExportStarsToExportValues?: boolean) { + if (compilerOptions.importHelpers && isEffectiveExternalModule(node, compilerOptions)) { const externalHelpersModuleName = getExternalHelpersModuleName(node); if (externalHelpersModuleName) { return externalHelpersModuleName; } - const helpers = getEmitHelpers(node); - if (helpers) { - for (const helper of helpers) { - if (!helper.scoped) { - const parseNode = getOriginalNode(node, isSourceFile); - const emitNode = getOrCreateEmitNode(parseNode); - return emitNode.externalHelpersModuleName || (emitNode.externalHelpersModuleName = createUniqueName(externalHelpersModuleNameText)); + const moduleKind = getEmitModuleKind(compilerOptions); + let create = hasExportStarsToExportValues + && moduleKind !== ModuleKind.System + && moduleKind !== ModuleKind.ES2015; + if (!create) { + const helpers = getEmitHelpers(node); + if (helpers) { + for (const helper of helpers) { + if (!helper.scoped) { + create = true; + break; + } } } } + + if (create) { + const parseNode = getOriginalNode(node, isSourceFile); + const emitNode = getOrCreateEmitNode(parseNode); + return emitNode.externalHelpersModuleName || (emitNode.externalHelpersModuleName = createUniqueName(externalHelpersModuleNameText)); + } } } + /** * Adds an EmitHelper to a node. */ @@ -3293,17 +3305,6 @@ namespace ts { let exportEquals: ExportAssignment = undefined; let hasExportStarsToExportValues = false; - const externalHelpersModuleName = getOrCreateExternalHelpersModuleNameIfNeeded(sourceFile, compilerOptions); - const externalHelpersImportDeclaration = externalHelpersModuleName && createImportDeclaration( - /*decorators*/ undefined, - /*modifiers*/ undefined, - createImportClause(/*name*/ undefined, createNamespaceImport(externalHelpersModuleName)), - createLiteral(externalHelpersModuleNameText)); - - if (externalHelpersImportDeclaration) { - externalImports.push(externalHelpersImportDeclaration); - } - for (const node of sourceFile.statements) { switch (node.kind) { case SyntaxKind.ImportDeclaration: @@ -3414,6 +3415,17 @@ namespace ts { } } + const externalHelpersModuleName = getOrCreateExternalHelpersModuleNameIfNeeded(sourceFile, compilerOptions, hasExportStarsToExportValues); + const externalHelpersImportDeclaration = externalHelpersModuleName && createImportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createImportClause(/*name*/ undefined, createNamespaceImport(externalHelpersModuleName)), + createLiteral(externalHelpersModuleNameText)); + + if (externalHelpersImportDeclaration) { + externalImports.unshift(externalHelpersImportDeclaration); + } + return { externalImports, exportSpecifiers, exportEquals, hasExportStarsToExportValues, exportedBindings, exportedNames, externalHelpersImportDeclaration }; } diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 170af0778ca..da8a55ed3bc 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -87,7 +87,7 @@ namespace ts { addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false); const updated = updateSourceFileNode(node, createNodeArray(statements, node.statements)); - if (currentModuleInfo.hasExportStarsToExportValues) { + if (currentModuleInfo.hasExportStarsToExportValues && !compilerOptions.importHelpers) { addEmitHelper(updated, exportStarHelper); } @@ -377,7 +377,7 @@ namespace ts { addExportEqualsIfNeeded(statements, /*emitAsReturn*/ true); const body = createBlock(statements, /*location*/ undefined, /*multiLine*/ true); - if (currentModuleInfo.hasExportStarsToExportValues) { + if (currentModuleInfo.hasExportStarsToExportValues && !compilerOptions.importHelpers) { // If we have any `export * from ...` declarations // we need to inform the emitter to add the __export helper. addEmitHelper(body, exportStarHelper); @@ -691,15 +691,7 @@ namespace ts { else { // export * from "mod"; return createStatement( - createCall( - createIdentifier("__export"), - /*typeArguments*/ undefined, - [ - moduleKind !== ModuleKind.AMD - ? createRequireCall(node) - : generatedName - ] - ), + createExportStarHelper(context, moduleKind !== ModuleKind.AMD ? createRequireCall(node) : generatedName), /*location*/ node ); } @@ -1441,6 +1433,14 @@ namespace ts { text: ` function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; - }` + } + ` }; + + function createExportStarHelper(context: TransformationContext, module: Expression) { + const compilerOptions = context.getCompilerOptions(); + return compilerOptions.importHelpers + ? createCall(getHelperName("__exportStar"), /*typeArguments*/ undefined, [module, createIdentifier("exports")]) + : createCall(createIdentifier("__export"), /*typeArguments*/ undefined, [module]); + } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6eebb0b99d7..26045ba1688 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3733,9 +3733,10 @@ namespace ts { Param = 1 << 5, // __param (used by TypeScript decorators transformation) Awaiter = 1 << 6, // __awaiter (used by ES2017 async functions transformation) Generator = 1 << 7, // __generator (used by ES2015 generator transformation) + ExportStar = 1 << 8, // __exportStar (used by CommonJS/AMD/UMD module transformation) FirstEmitHelper = Extends, - LastEmitHelper = Generator + LastEmitHelper = ExportStar } /* @internal */ diff --git a/tests/baselines/reference/importHelpersAmd.js b/tests/baselines/reference/importHelpersAmd.js index fea93840fa9..96d398e05eb 100644 --- a/tests/baselines/reference/importHelpersAmd.js +++ b/tests/baselines/reference/importHelpersAmd.js @@ -5,16 +5,19 @@ export class A { } //// [b.ts] import { A } from "./a"; +export * from "./a"; export class B extends A { } //// [tslib.d.ts] export declare function __extends(d: Function, b: Function): void; export declare function __assign(t: any, ...sources: any[]): any; +export declare function __rest(t: any, propertyNames: string[]): any; export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; export declare function __param(paramIndex: number, decorator: Function): Function; export declare function __metadata(metadataKey: any, metadataValue: any): Function; export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; - +export declare function __generator(thisArg: any, body: Function): any; +export declare function __exportStar(m: any, exports: any): void; //// [a.js] define(["require", "exports"], function (require, exports) { @@ -27,8 +30,9 @@ define(["require", "exports"], function (require, exports) { exports.A = A; }); //// [b.js] -define(["require", "exports", "tslib", "./a"], function (require, exports, tslib_1, a_1) { +define(["require", "exports", "tslib", "./a", "./a"], function (require, exports, tslib_1, a_1, a_2) { "use strict"; + tslib_1.__exportStar(a_2, exports); var B = (function (_super) { tslib_1.__extends(B, _super); function B() { diff --git a/tests/baselines/reference/importHelpersAmd.symbols b/tests/baselines/reference/importHelpersAmd.symbols index 47528a8bba6..68506b4c353 100644 --- a/tests/baselines/reference/importHelpersAmd.symbols +++ b/tests/baselines/reference/importHelpersAmd.symbols @@ -6,8 +6,9 @@ export class A { } import { A } from "./a"; >A : Symbol(A, Decl(b.ts, 0, 8)) +export * from "./a"; export class B extends A { } ->B : Symbol(B, Decl(b.ts, 0, 24)) +>B : Symbol(B, Decl(b.ts, 1, 20)) >A : Symbol(A, Decl(b.ts, 0, 8)) === tests/cases/compiler/tslib.d.ts === @@ -23,6 +24,11 @@ export declare function __assign(t: any, ...sources: any[]): any; >t : Symbol(t, Decl(tslib.d.ts, --, --)) >sources : Symbol(sources, Decl(tslib.d.ts, --, --)) +export declare function __rest(t: any, propertyNames: string[]): any; +>__rest : Symbol(__rest, Decl(tslib.d.ts, --, --)) +>t : Symbol(t, Decl(tslib.d.ts, --, --)) +>propertyNames : Symbol(propertyNames, Decl(tslib.d.ts, --, --)) + export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; >__decorate : Symbol(__decorate, Decl(tslib.d.ts, --, --)) >decorators : Symbol(decorators, Decl(tslib.d.ts, --, --)) @@ -53,3 +59,14 @@ export declare function __awaiter(thisArg: any, _arguments: any, P: Function, ge >generator : Symbol(generator, Decl(tslib.d.ts, --, --)) >Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +export declare function __generator(thisArg: any, body: Function): any; +>__generator : Symbol(__generator, Decl(tslib.d.ts, --, --)) +>thisArg : Symbol(thisArg, Decl(tslib.d.ts, --, --)) +>body : Symbol(body, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __exportStar(m: any, exports: any): void; +>__exportStar : Symbol(__exportStar, Decl(tslib.d.ts, --, --)) +>m : Symbol(m, Decl(tslib.d.ts, --, --)) +>exports : Symbol(exports, Decl(tslib.d.ts, --, --)) + diff --git a/tests/baselines/reference/importHelpersAmd.types b/tests/baselines/reference/importHelpersAmd.types index 9ff756ffaab..23456ae2333 100644 --- a/tests/baselines/reference/importHelpersAmd.types +++ b/tests/baselines/reference/importHelpersAmd.types @@ -6,6 +6,7 @@ export class A { } import { A } from "./a"; >A : typeof A +export * from "./a"; export class B extends A { } >B : B >A : A @@ -23,6 +24,11 @@ export declare function __assign(t: any, ...sources: any[]): any; >t : any >sources : any[] +export declare function __rest(t: any, propertyNames: string[]): any; +>__rest : (t: any, propertyNames: string[]) => any +>t : any +>propertyNames : string[] + export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; >__decorate : (decorators: Function[], target: any, key?: string | symbol, desc?: any) => any >decorators : Function[] @@ -53,3 +59,14 @@ export declare function __awaiter(thisArg: any, _arguments: any, P: Function, ge >generator : Function >Function : Function +export declare function __generator(thisArg: any, body: Function): any; +>__generator : (thisArg: any, body: Function) => any +>thisArg : any +>body : Function +>Function : Function + +export declare function __exportStar(m: any, exports: any): void; +>__exportStar : (m: any, exports: any) => void +>m : any +>exports : any + diff --git a/tests/baselines/reference/importHelpersInAmbientContext.js b/tests/baselines/reference/importHelpersInAmbientContext.js index b9db8c4751f..9433b41d117 100644 --- a/tests/baselines/reference/importHelpersInAmbientContext.js +++ b/tests/baselines/reference/importHelpersInAmbientContext.js @@ -49,11 +49,13 @@ declare namespace N { //// [tslib.d.ts] export declare function __extends(d: Function, b: Function): void; export declare function __assign(t: any, ...sources: any[]): any; +export declare function __rest(t: any, propertyNames: string[]): any; export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; export declare function __param(paramIndex: number, decorator: Function): Function; export declare function __metadata(metadataKey: any, metadataValue: any): Function; export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; - +export declare function __generator(thisArg: any, body: Function): any; +export declare function __exportStar(m: any, exports: any): void; //// [b.js] "use strict"; diff --git a/tests/baselines/reference/importHelpersInAmbientContext.symbols b/tests/baselines/reference/importHelpersInAmbientContext.symbols index 7da1ea95042..5b9b7e61e71 100644 --- a/tests/baselines/reference/importHelpersInAmbientContext.symbols +++ b/tests/baselines/reference/importHelpersInAmbientContext.symbols @@ -99,6 +99,11 @@ export declare function __assign(t: any, ...sources: any[]): any; >t : Symbol(t, Decl(tslib.d.ts, --, --)) >sources : Symbol(sources, Decl(tslib.d.ts, --, --)) +export declare function __rest(t: any, propertyNames: string[]): any; +>__rest : Symbol(__rest, Decl(tslib.d.ts, --, --)) +>t : Symbol(t, Decl(tslib.d.ts, --, --)) +>propertyNames : Symbol(propertyNames, Decl(tslib.d.ts, --, --)) + export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; >__decorate : Symbol(__decorate, Decl(tslib.d.ts, --, --)) >decorators : Symbol(decorators, Decl(tslib.d.ts, --, --)) @@ -129,3 +134,14 @@ export declare function __awaiter(thisArg: any, _arguments: any, P: Function, ge >generator : Symbol(generator, Decl(tslib.d.ts, --, --)) >Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +export declare function __generator(thisArg: any, body: Function): any; +>__generator : Symbol(__generator, Decl(tslib.d.ts, --, --)) +>thisArg : Symbol(thisArg, Decl(tslib.d.ts, --, --)) +>body : Symbol(body, Decl(tslib.d.ts, --, --)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +export declare function __exportStar(m: any, exports: any): void; +>__exportStar : Symbol(__exportStar, Decl(tslib.d.ts, --, --)) +>m : Symbol(m, Decl(tslib.d.ts, --, --)) +>exports : Symbol(exports, Decl(tslib.d.ts, --, --)) + diff --git a/tests/baselines/reference/importHelpersInAmbientContext.types b/tests/baselines/reference/importHelpersInAmbientContext.types index 5f3102b68f5..ac0803e6bd7 100644 --- a/tests/baselines/reference/importHelpersInAmbientContext.types +++ b/tests/baselines/reference/importHelpersInAmbientContext.types @@ -99,6 +99,11 @@ export declare function __assign(t: any, ...sources: any[]): any; >t : any >sources : any[] +export declare function __rest(t: any, propertyNames: string[]): any; +>__rest : (t: any, propertyNames: string[]) => any +>t : any +>propertyNames : string[] + export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; >__decorate : (decorators: Function[], target: any, key?: string | symbol, desc?: any) => any >decorators : Function[] @@ -129,3 +134,14 @@ export declare function __awaiter(thisArg: any, _arguments: any, P: Function, ge >generator : Function >Function : Function +export declare function __generator(thisArg: any, body: Function): any; +>__generator : (thisArg: any, body: Function) => any +>thisArg : any +>body : Function +>Function : Function + +export declare function __exportStar(m: any, exports: any): void; +>__exportStar : (m: any, exports: any) => void +>m : any +>exports : any + diff --git a/tests/baselines/reference/importHelpersNoHelpers.errors.txt b/tests/baselines/reference/importHelpersNoHelpers.errors.txt index a0c089a9ddc..4034fbc649b 100644 --- a/tests/baselines/reference/importHelpersNoHelpers.errors.txt +++ b/tests/baselines/reference/importHelpersNoHelpers.errors.txt @@ -1,12 +1,16 @@ -tests/cases/compiler/external.ts(2,16): error TS2343: This syntax requires an imported helper named '__extends', but module 'tslib' has no exported member '__extends'. -tests/cases/compiler/external.ts(6,1): error TS2343: This syntax requires an imported helper named '__decorate', but module 'tslib' has no exported member '__decorate'. -tests/cases/compiler/external.ts(6,1): error TS2343: This syntax requires an imported helper named '__metadata', but module 'tslib' has no exported member '__metadata'. -tests/cases/compiler/external.ts(8,12): error TS2343: This syntax requires an imported helper named '__param', but module 'tslib' has no exported member '__param'. -tests/cases/compiler/external.ts(13,13): error TS2343: This syntax requires an imported helper named '__assign', but module 'tslib' has no exported member '__assign'. -tests/cases/compiler/external.ts(14,12): error TS2343: This syntax requires an imported helper named '__rest', but module 'tslib' has no exported member '__rest'. +tests/cases/compiler/external.ts(1,1): error TS2343: This syntax requires an imported helper named '__exportStar', but module 'tslib' has no exported member '__exportStar'. +tests/cases/compiler/external.ts(3,16): error TS2343: This syntax requires an imported helper named '__extends', but module 'tslib' has no exported member '__extends'. +tests/cases/compiler/external.ts(7,1): error TS2343: This syntax requires an imported helper named '__decorate', but module 'tslib' has no exported member '__decorate'. +tests/cases/compiler/external.ts(7,1): error TS2343: This syntax requires an imported helper named '__metadata', but module 'tslib' has no exported member '__metadata'. +tests/cases/compiler/external.ts(9,12): error TS2343: This syntax requires an imported helper named '__param', but module 'tslib' has no exported member '__param'. +tests/cases/compiler/external.ts(14,13): error TS2343: This syntax requires an imported helper named '__assign', but module 'tslib' has no exported member '__assign'. +tests/cases/compiler/external.ts(15,12): error TS2343: This syntax requires an imported helper named '__rest', but module 'tslib' has no exported member '__rest'. -==== tests/cases/compiler/external.ts (6 errors) ==== +==== tests/cases/compiler/external.ts (7 errors) ==== + export * from "./other"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2343: This syntax requires an imported helper named '__exportStar', but module 'tslib' has no exported member '__exportStar'. export class A { } export class B extends A { } ~~~~~~~~~ @@ -34,6 +38,9 @@ tests/cases/compiler/external.ts(14,12): error TS2343: This syntax requires an i ~ !!! error TS2343: This syntax requires an imported helper named '__rest', but module 'tslib' has no exported member '__rest'. +==== tests/cases/compiler/other.ts (0 errors) ==== + export const x = 1; + ==== tests/cases/compiler/script.ts (0 errors) ==== class A { } class B extends A { } diff --git a/tests/baselines/reference/importHelpersNoHelpers.js b/tests/baselines/reference/importHelpersNoHelpers.js index 560e16d1cca..ae709c086ba 100644 --- a/tests/baselines/reference/importHelpersNoHelpers.js +++ b/tests/baselines/reference/importHelpersNoHelpers.js @@ -1,6 +1,7 @@ //// [tests/cases/compiler/importHelpersNoHelpers.ts] //// //// [external.ts] +export * from "./other"; export class A { } export class B extends A { } @@ -16,6 +17,9 @@ const o = { a: 1 }; const y = { ...o }; const { ...x } = y; +//// [other.ts] +export const x = 1; + //// [script.ts] class A { } class B extends A { } @@ -32,9 +36,13 @@ class C { export {} +//// [other.js] +"use strict"; +exports.x = 1; //// [external.js] "use strict"; var tslib_1 = require("tslib"); +tslib_1.__exportStar(require("./other"), exports); var A = (function () { function A() { } diff --git a/tests/baselines/reference/importHelpersSystem.js b/tests/baselines/reference/importHelpersSystem.js index 20f2d299c52..43556ae6b76 100644 --- a/tests/baselines/reference/importHelpersSystem.js +++ b/tests/baselines/reference/importHelpersSystem.js @@ -5,6 +5,7 @@ export class A { } //// [b.ts] import { A } from "./a"; +export * from "./a"; export class B extends A { } //// [tslib.d.ts] @@ -38,6 +39,16 @@ System.register(["tslib", "./a"], function (exports_1, context_1) { "use strict"; var __moduleName = context_1 && context_1.id; var tslib_1, a_1, B; + var exportedNames_1 = { + "B": true + }; + function exportStar_1(m) { + var exports = {}; + for (var n in m) { + if (n !== "default" && !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; + } + exports_1(exports); + } return { setters: [ function (tslib_1_1) { @@ -45,6 +56,7 @@ System.register(["tslib", "./a"], function (exports_1, context_1) { }, function (a_1_1) { a_1 = a_1_1; + exportStar_1(a_1_1); } ], execute: function () { diff --git a/tests/baselines/reference/importHelpersSystem.symbols b/tests/baselines/reference/importHelpersSystem.symbols index 47528a8bba6..d7d588a67ef 100644 --- a/tests/baselines/reference/importHelpersSystem.symbols +++ b/tests/baselines/reference/importHelpersSystem.symbols @@ -6,8 +6,9 @@ export class A { } import { A } from "./a"; >A : Symbol(A, Decl(b.ts, 0, 8)) +export * from "./a"; export class B extends A { } ->B : Symbol(B, Decl(b.ts, 0, 24)) +>B : Symbol(B, Decl(b.ts, 1, 20)) >A : Symbol(A, Decl(b.ts, 0, 8)) === tests/cases/compiler/tslib.d.ts === diff --git a/tests/baselines/reference/importHelpersSystem.types b/tests/baselines/reference/importHelpersSystem.types index 9ff756ffaab..de9ef3e9446 100644 --- a/tests/baselines/reference/importHelpersSystem.types +++ b/tests/baselines/reference/importHelpersSystem.types @@ -6,6 +6,7 @@ export class A { } import { A } from "./a"; >A : typeof A +export * from "./a"; export class B extends A { } >B : B >A : A diff --git a/tests/cases/compiler/importHelpersAmd.ts b/tests/cases/compiler/importHelpersAmd.ts index bef63328d52..38b02424b96 100644 --- a/tests/cases/compiler/importHelpersAmd.ts +++ b/tests/cases/compiler/importHelpersAmd.ts @@ -6,12 +6,16 @@ export class A { } // @filename: b.ts import { A } from "./a"; +export * from "./a"; export class B extends A { } // @filename: tslib.d.ts export declare function __extends(d: Function, b: Function): void; export declare function __assign(t: any, ...sources: any[]): any; +export declare function __rest(t: any, propertyNames: string[]): any; export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; export declare function __param(paramIndex: number, decorator: Function): Function; export declare function __metadata(metadataKey: any, metadataValue: any): Function; export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +export declare function __generator(thisArg: any, body: Function): any; +export declare function __exportStar(m: any, exports: any): void; \ No newline at end of file diff --git a/tests/cases/compiler/importHelpersInAmbientContext.ts b/tests/cases/compiler/importHelpersInAmbientContext.ts index 8bfa5b25404..340961802a3 100644 --- a/tests/cases/compiler/importHelpersInAmbientContext.ts +++ b/tests/cases/compiler/importHelpersInAmbientContext.ts @@ -49,7 +49,10 @@ declare namespace N { // @filename: tslib.d.ts export declare function __extends(d: Function, b: Function): void; export declare function __assign(t: any, ...sources: any[]): any; +export declare function __rest(t: any, propertyNames: string[]): any; export declare function __decorate(decorators: Function[], target: any, key?: string | symbol, desc?: any): any; export declare function __param(paramIndex: number, decorator: Function): Function; export declare function __metadata(metadataKey: any, metadataValue: any): Function; export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; +export declare function __generator(thisArg: any, body: Function): any; +export declare function __exportStar(m: any, exports: any): void; \ No newline at end of file diff --git a/tests/cases/compiler/importHelpersNoHelpers.ts b/tests/cases/compiler/importHelpersNoHelpers.ts index 4ab48aba7df..787058890a2 100644 --- a/tests/cases/compiler/importHelpersNoHelpers.ts +++ b/tests/cases/compiler/importHelpersNoHelpers.ts @@ -5,6 +5,7 @@ // @experimentalDecorators: true // @emitDecoratorMetadata: true // @filename: external.ts +export * from "./other"; export class A { } export class B extends A { } @@ -20,6 +21,9 @@ const o = { a: 1 }; const y = { ...o }; const { ...x } = y; +// @filename: other.ts +export const x = 1; + // @filename: script.ts class A { } class B extends A { } diff --git a/tests/cases/compiler/importHelpersSystem.ts b/tests/cases/compiler/importHelpersSystem.ts index 5b6081f17f3..87e62785708 100644 --- a/tests/cases/compiler/importHelpersSystem.ts +++ b/tests/cases/compiler/importHelpersSystem.ts @@ -6,6 +6,7 @@ export class A { } // @filename: b.ts import { A } from "./a"; +export * from "./a"; export class B extends A { } // @filename: tslib.d.ts From 893ba1de1543787f6a36c8dd59e676ea58b59102 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 24 May 2017 15:24:49 -0700 Subject: [PATCH 002/138] Filter symbols based on the meaning at the location --- Jakefile.js | 2 +- src/compiler/checker.ts | 23 +- src/services/completions.ts | 121 ++++++++-- src/services/utilities.ts | 4 +- tests/cases/fourslash/commentsInheritance.ts | 6 +- tests/cases/fourslash/commentsInterface.ts | 8 +- tests/cases/fourslash/commentsOverloads.ts | 8 +- .../fourslash/completionListAfterFunction2.ts | 3 +- .../cases/fourslash/completionListCladule.ts | 6 +- ...nListInClassExpressionWithTypeParameter.ts | 5 +- ...tInClosedObjectTypeLiteralInSignature01.ts | 4 +- ...tInClosedObjectTypeLiteralInSignature02.ts | 4 +- ...tInClosedObjectTypeLiteralInSignature03.ts | 4 +- .../completionListInExtendsClause.ts | 2 +- .../cases/fourslash/completionListInScope.ts | 6 +- ...mpletionListInTypeParameterOfTypeAlias1.ts | 4 +- ...mpletionListInTypeParameterOfTypeAlias2.ts | 8 +- ...mpletionListInTypeParameterOfTypeAlias3.ts | 14 +- ...ompletionListInUnclosedIndexSignature02.ts | 2 +- ...nUnclosedObjectTypeLiteralInSignature01.ts | 4 +- ...nUnclosedObjectTypeLiteralInSignature02.ts | 4 +- ...nUnclosedObjectTypeLiteralInSignature03.ts | 4 +- .../fourslash/completionListModuleMembers.ts | 60 ++--- ...ionListNewIdentifierVariableDeclaration.ts | 13 +- .../fourslash/completionListOnAliases2.ts | 49 ++-- .../fourslash/completionListOnParamInClass.ts | 4 +- .../fourslash/completionListWithMeanings.ts | 68 ++++++ .../completionListWithModulesFromModule.ts | 121 ++++++---- ...pletionListWithModulesInsideModuleScope.ts | 211 +++++++++++------- ...letionListWithModulesOutsideModuleScope.ts | 2 +- ...etionListWithModulesOutsideModuleScope2.ts | 2 +- .../completionWithNamespaceInsideFunction.ts | 30 ++- .../externalModuleWithExportAssignment.ts | 4 +- tests/cases/fourslash/memberListOfModule.ts | 4 +- 34 files changed, 558 insertions(+), 256 deletions(-) create mode 100644 tests/cases/fourslash/completionListWithMeanings.ts diff --git a/Jakefile.js b/Jakefile.js index f1a714c1e26..fe0d5f7352e 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -954,7 +954,7 @@ var nodeServerInFile = "tests/webTestServer.ts"; compileFile(nodeServerOutFile, [nodeServerInFile], [builtLocalDirectory, tscFile], [], /*useBuiltCompiler:*/ true, { noOutFile: true, lib: "es6" }); desc("Runs browserify on run.js to produce a file suitable for running tests in the browser"); -task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() { +task("browserify", ["tests", run, builtLocalDirectory, nodeServerOutFile], function() { var cmd = 'browserify built/local/run.js -t ./scripts/browserify-optional -d -o built/local/bundle.js'; exec(cmd); }, { async: true }); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cfe2c5a6bf2..58ffc78f889 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14554,12 +14554,31 @@ namespace ts { ? (node).expression : (node).left; - const type = checkExpression(left); + return isValidPropertyAccessWithType(node, left, propertyName, getWidenedType(checkExpression(left))); + } + + function isValidPropertyAccessWithType( + node: PropertyAccessExpression | QualifiedName, + left: LeftHandSideExpression | QualifiedName, + propertyName: string, + type: Type): boolean { + if (type !== unknownType && !isTypeAny(type)) { - const prop = getPropertyOfType(getWidenedType(type), propertyName); + const prop = getPropertyOfType(type, propertyName); if (prop) { return checkPropertyAccessibility(node, left, type, prop); } + + // In js files properties of unions are allowed in completion + if (isInJavaScriptFile(left) && (type.flags & TypeFlags.Union)) { + for (const elementType of (type).types) { + if (isValidPropertyAccessWithType(node, left, propertyName, elementType)) { + return true; + } + } + } + + return false; } return true; } diff --git a/src/services/completions.ts b/src/services/completions.ts index a895be8a7da..94935d3f3db 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -559,6 +559,9 @@ namespace ts.Completions { isMemberCompletion = true; isNewIdentifierLocation = false; + // Since this is qualified name check its a type node location + const isTypeLocation = isPartOfTypeNode(node.parent); + const isRhsOfImportDeclaration = isInRightSideOfInternalImportEqualsDeclaration(node); if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression) { let symbol = typeChecker.getSymbolAtLocation(node); @@ -570,16 +573,24 @@ namespace ts.Completions { if (symbol && symbol.flags & SymbolFlags.HasExports) { // Extract module or enum members const exportedSymbols = typeChecker.getExportsOfModule(symbol); + const isValidValueAccess = (symbol: Symbol) => typeChecker.isValidPropertyAccess((node.parent), symbol.name); + const isValidTypeAccess = (symbol: Symbol) => symbolCanbeReferencedAtTypeLocation(symbol); + const isValidAccess = isRhsOfImportDeclaration ? + // Any kind is allowed when dotting off namespace in internal import equals declaration + (symbol: Symbol) => isValidTypeAccess(symbol) || isValidValueAccess(symbol) : + isTypeLocation ? isValidTypeAccess : isValidValueAccess; forEach(exportedSymbols, symbol => { - if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { + if (isValidAccess(symbol)) { symbols.push(symbol); } }); } } - const type = typeChecker.getTypeAtLocation(node); - addTypeProperties(type); + if (!isTypeLocation) { + const type = typeChecker.getTypeAtLocation(node); + addTypeProperties(type); + } } function addTypeProperties(type: Type) { @@ -687,13 +698,88 @@ namespace ts.Completions { isStatement(scopeNode); } - /// TODO filter meaning based on the current context const symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; - symbols = typeChecker.getSymbolsInScope(scopeNode, symbolMeanings); + symbols = filterGlobalCompletion(typeChecker.getSymbolsInScope(scopeNode, symbolMeanings)); return true; } + function filterGlobalCompletion(symbols: Symbol[]) { + return filter(symbols, symbol => { + if (!isSourceFile(location)) { + // export = /**/ here we want to get all meanings, so any symbol is ok + if (isExportAssignment(location.parent)) { + return true; + } + + // This is an alias, follow what it aliases + if (symbol && symbol.flags & SymbolFlags.Alias) { + symbol = typeChecker.getAliasedSymbol(symbol); + } + + // import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace) + if (isInRightSideOfInternalImportEqualsDeclaration(location)) { + return !!(symbol.flags & SymbolFlags.Namespace); + } + + if (!isContextTokenValueLocation(contextToken) && + (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken))) { + // Its a type, but you can reach it by namespace.type as well + return symbolCanbeReferencedAtTypeLocation(symbol); + } + } + + // expressions are value space (which includes the value namespaces) + return !!(symbol.flags & SymbolFlags.Value); + }); + } + + function isContextTokenValueLocation(contextToken: Node) { + if (contextToken) { + const parentKind = contextToken.parent.kind; + switch (contextToken.kind) { + case SyntaxKind.TypeOfKeyword: + return parentKind === SyntaxKind.TypeQuery; + } + } + } + + function isContextTokenTypeLocation(contextToken: Node) { + if (contextToken) { + const parentKind = contextToken.parent.kind; + switch (contextToken.kind) { + case SyntaxKind.ColonToken: + return parentKind === SyntaxKind.PropertyDeclaration || + parentKind === SyntaxKind.PropertySignature || + parentKind === SyntaxKind.Parameter || + parentKind === SyntaxKind.VariableDeclaration || + isFunctionLikeKind(parentKind); + + case SyntaxKind.EqualsToken: + return parentKind === SyntaxKind.TypeAliasDeclaration; + + case SyntaxKind.AsKeyword: + return parentKind === SyntaxKind.AsExpression; + } + } + } + + function symbolCanbeReferencedAtTypeLocation(symbol: Symbol): boolean { + // This is an alias, follow what it aliases + if (symbol && symbol.flags & SymbolFlags.Alias) { + symbol = typeChecker.getAliasedSymbol(symbol); + } + + if (symbol.flags & (SymbolFlags.ValueModule | SymbolFlags.NamespaceModule)) { + const exportedSymbols = typeChecker.getExportsOfModule(symbol); + // If the exported symbols contains type, + // symbol can be referenced at locations where type is allowed + return forEach(exportedSymbols, symbolCanbeReferencedAtTypeLocation); + } + + return !!(symbol.flags & (SymbolFlags.NamespaceModule | SymbolFlags.Type)); + } + /** * Finds the first node that "embraces" the position, so that one may * accurately aggregate locals from the closest containing scope. @@ -1126,21 +1212,6 @@ namespace ts.Completions { return undefined; } - function isFunction(kind: SyntaxKind): boolean { - if (!isFunctionLikeKind(kind)) { - return false; - } - - switch (kind) { - case SyntaxKind.Constructor: - case SyntaxKind.ConstructorType: - case SyntaxKind.FunctionType: - return false; - default: - return true; - } - } - /** * @returns true if we are certain that the currently edited location must define a new location; false otherwise. */ @@ -1152,7 +1223,7 @@ namespace ts.Completions { containingNodeKind === SyntaxKind.VariableDeclarationList || containingNodeKind === SyntaxKind.VariableStatement || containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { foo, | - isFunction(containingNodeKind) || + isFunctionLikeButNotConstructor(containingNodeKind) || containingNodeKind === SyntaxKind.ClassDeclaration || // class A string", ""); @@ -194,7 +194,7 @@ verify.completionListContains("a", "(parameter) a: number", "i3_i a"); verify.quickInfoAt("40q", "var i3_i: i3"); goTo.marker('40'); -verify.completionListContains("i3", "interface i3", ""); +verify.not.completionListContains("i3", "interface i3", ""); verify.completionListContains("i3_i", "var i3_i: i3", ""); goTo.marker('41'); diff --git a/tests/cases/fourslash/commentsOverloads.ts b/tests/cases/fourslash/commentsOverloads.ts index ec4a63349f9..6add2609897 100644 --- a/tests/cases/fourslash/commentsOverloads.ts +++ b/tests/cases/fourslash/commentsOverloads.ts @@ -295,13 +295,13 @@ verify.completionListContains('f3', 'function f3(a: number): number (+1 overload verify.completionListContains('f4', 'function f4(a: number): number (+1 overload)', 'this is signature 4 - with number parameter'); goTo.marker('18'); -verify.completionListContains('i1', 'interface i1', ''); +verify.not.completionListContains('i1', 'interface i1', ''); verify.completionListContains('i1_i', 'var i1_i: new i1(b: number) => any (+1 overload)', ''); -verify.completionListContains('i2', 'interface i2', ''); +verify.not.completionListContains('i2', 'interface i2', ''); verify.completionListContains('i2_i', 'var i2_i: new i2(a: string) => any (+1 overload)', ''); -verify.completionListContains('i3', 'interface i3', ''); +verify.not.completionListContains('i3', 'interface i3', ''); verify.completionListContains('i3_i', 'var i3_i: new i3(a: string) => any (+1 overload)', 'new 1'); -verify.completionListContains('i4', 'interface i4', ''); +verify.not.completionListContains('i4', 'interface i4', ''); verify.completionListContains('i4_i', 'var i4_i: new i4(a: string) => any (+1 overload)', ''); goTo.marker('19'); diff --git a/tests/cases/fourslash/completionListAfterFunction2.ts b/tests/cases/fourslash/completionListAfterFunction2.ts index c123e084972..0dfbd4fb461 100644 --- a/tests/cases/fourslash/completionListAfterFunction2.ts +++ b/tests/cases/fourslash/completionListAfterFunction2.ts @@ -9,5 +9,6 @@ goTo.marker("1"); verify.not.completionListContains("a"); goTo.marker("2"); +verify.not.completionListContains("b"); +edit.insert("typeof "); verify.completionListContains("b"); - diff --git a/tests/cases/fourslash/completionListCladule.ts b/tests/cases/fourslash/completionListCladule.ts index 4225e6be263..6d9e9145b66 100644 --- a/tests/cases/fourslash/completionListCladule.ts +++ b/tests/cases/fourslash/completionListCladule.ts @@ -8,7 +8,7 @@ //// export var x: number; ////} ////Foo/*c1*/; // should get "x", "prototype" -////var s: Foo/*c2*/; // should get "x" and "prototype" +////var s: Foo/*c2*/; // no types, in Foo, so shouldnt have anything ////var f = new Foo(); ////f/*c3*/; @@ -20,9 +20,7 @@ verify.completionListContains("staticMethod"); goTo.marker("c2"); edit.insert("."); -verify.completionListContains("x"); -verify.completionListContains("staticMethod"); -verify.completionListContains("prototype"); +verify.completionListIsEmpty(); goTo.marker("c3"); edit.insert("."); diff --git a/tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts b/tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts index 6f016b73a76..47f030bf907 100644 --- a/tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts +++ b/tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts @@ -1,13 +1,16 @@ -/// +/// //// var x = class myClass { //// getClassName (){ //// /*0*/ +//// var tmp: /*0Type*/; //// } //// prop: Ty/*1*/ //// } goTo.marker("0"); +verify.not.completionListContains("TypeParam", "(type parameter) TypeParam in myClass", /*documentation*/ undefined, "type parameter"); +goTo.marker("0Type"); verify.completionListContains("TypeParam", "(type parameter) TypeParam in myClass", /*documentation*/ undefined, "type parameter"); goTo.marker("1"); diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts index 08f3b0e16b2..856d94492e6 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts @@ -14,5 +14,5 @@ verify.completionListContains("TString"); verify.completionListContains("TNumber"); // Ideally the following shouldn't show up since they're not types. -verify.completionListContains("foo"); -verify.completionListContains("obj"); \ No newline at end of file +verify.not.completionListContains("foo"); +verify.not.completionListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts index 36e9dc759e7..0472a9c04fa 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts @@ -14,5 +14,5 @@ verify.completionListContains("TString"); verify.completionListContains("TNumber"); // REVIEW: Is this intended behavior? // Ideally the following shouldn't show up since they're not types. -verify.completionListContains("foo"); -verify.completionListContains("obj"); \ No newline at end of file +verify.not.completionListContains("foo"); +verify.not.completionListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts index 388385f4c39..1dc34dcffd4 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts @@ -14,5 +14,5 @@ verify.completionListContains("TString"); verify.completionListContains("TNumber"); // REVIEW: Is this intended behavior? // Ideally the following shouldn't show up since they're not types. -verify.completionListContains("foo"); -verify.completionListContains("obj"); \ No newline at end of file +verify.not.completionListContains("foo"); +verify.not.completionListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInExtendsClause.ts b/tests/cases/fourslash/completionListInExtendsClause.ts index b765f77d5d0..79451e4fd57 100644 --- a/tests/cases/fourslash/completionListInExtendsClause.ts +++ b/tests/cases/fourslash/completionListInExtendsClause.ts @@ -27,4 +27,4 @@ goTo.marker("3"); verify.completionListIsEmpty(); goTo.marker("4"); -verify.not.completionListIsEmpty(); \ No newline at end of file +verify.completionListIsEmpty(); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInScope.ts b/tests/cases/fourslash/completionListInScope.ts index 7488db8dd42..8773f6d4588 100644 --- a/tests/cases/fourslash/completionListInScope.ts +++ b/tests/cases/fourslash/completionListInScope.ts @@ -85,11 +85,11 @@ verify.completionListContains("exportedInterface"); verify.completionListContains("localClass"); verify.completionListContains("exportedClass"); -verify.completionListContains("localModule"); -verify.completionListContains("exportedModule"); +verify.not.completionListContains("localModule"); +verify.not.completionListContains("exportedModule"); verify.completionListContains("exportedClass2"); -verify.completionListContains("exportedModule2"); +verify.not.completionListContains("exportedModule2"); goTo.marker("insideMethod"); verify.not.completionListContains("property"); diff --git a/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias1.ts b/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias1.ts index e6017eedbfc..57931c7b6d1 100644 --- a/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias1.ts +++ b/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias1.ts @@ -1,4 +1,4 @@ -/// +/// ////type List1 = T[]; @@ -8,7 +8,7 @@ goTo.marker("0"); verify.completionListIsEmpty(); goTo.marker("1"); -verify.not.completionListIsEmpty(); +verify.completionListIsEmpty(); goTo.marker("2"); verify.completionListContains("T"); goTo.marker("3"); diff --git a/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias2.ts b/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias2.ts index 80a910da798..44f7342029e 100644 --- a/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias2.ts +++ b/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias2.ts @@ -1,4 +1,4 @@ -/// +/// ////type Map1 = []; @@ -8,12 +8,12 @@ goTo.marker("0"); verify.completionListIsEmpty(); goTo.marker("1"); -verify.completionListContains("V"); +verify.completionListIsEmpty(); goTo.marker("2"); verify.completionListContains("K"); verify.completionListContains("V"); goTo.marker("3"); verify.not.completionListContains("K"); verify.not.completionListContains("V"); -verify.completionListContains("K1"); -verify.completionListContains("V1"); \ No newline at end of file +verify.not.completionListContains("K1"); +verify.not.completionListContains("V1"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias3.ts b/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias3.ts index e3831742257..a523aec98b3 100644 --- a/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias3.ts +++ b/tests/cases/fourslash/completionListInTypeParameterOfTypeAlias3.ts @@ -1,13 +1,13 @@ -/// +/// //// type constructorType = new +/// ////var x : (s/*1*/ ////var y : (s:string, list/*2*/ -goTo.eachMarker(() => { - verify.not.completionListIsEmpty(); - verify.completionListAllowsNewIdentifier(); -}); +goTo.marker("1"); +verify.not.completionListIsEmpty();// As this can either be type or become arrow function parameter +verify.completionListAllowsNewIdentifier(); + +goTo.marker("2"); +verify.completionListIsEmpty(); // Parameter name +verify.completionListAllowsNewIdentifier(); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOnAliases2.ts b/tests/cases/fourslash/completionListOnAliases2.ts index 7ff50a1a2b5..63f895f276e 100644 --- a/tests/cases/fourslash/completionListOnAliases2.ts +++ b/tests/cases/fourslash/completionListOnAliases2.ts @@ -25,23 +25,47 @@ ////import a = M.A; //// ////m./*1*/; +////var tmp: m./*1Type*/; ////c./*2*/; ////e./*3*/; ////n./*4*/; ////v./*5*/; ////f./*6*/; ////a./*7*/; +////var tmp2: a./*7Type*/; + +function getVerify(isTypeLocation?: boolean) { + return { + verifyValue: isTypeLocation ? verify.not : verify, + verifyType: isTypeLocation ? verify : verify.not, + verifyValueOrType: verify + }; +} +function typeLocationVerify(valueMarker: string, verify: (typeMarker: string) => void) { + verify(valueMarker + "Type"); + return valueMarker; +} + +function verifyModuleM(marker: string) { + const isTypeLocation = marker.indexOf("Type") !== -1; + const { verifyValue, verifyType, verifyValueOrType } = getVerify(isTypeLocation); + if (!isTypeLocation) { + marker = typeLocationVerify(marker, verifyModuleM); + } + goTo.marker(marker); + + verifyType.completionListContains("I"); + verifyValueOrType.completionListContains("C"); + verifyValueOrType.completionListContains("E"); + verifyValue.completionListContains("N"); + verifyValue.completionListContains("V"); + verifyValue.completionListContains("F"); + verifyValueOrType.completionListContains("A"); +} // Module m -goTo.marker("1"); -verify.completionListContains("I"); -verify.completionListContains("C"); -verify.completionListContains("E"); -verify.completionListContains("N"); -verify.completionListContains("V"); -verify.completionListContains("F"); -verify.completionListContains("A"); +verifyModuleM("1"); // Class C goTo.marker("2"); @@ -64,11 +88,4 @@ goTo.marker("6"); verify.completionListContains("call"); // alias a -goTo.marker("7"); -verify.completionListContains("I"); -verify.completionListContains("C"); -verify.completionListContains("E"); -verify.completionListContains("N"); -verify.completionListContains("V"); -verify.completionListContains("F"); -verify.completionListContains("A"); +verifyModuleM("7"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOnParamInClass.ts b/tests/cases/fourslash/completionListOnParamInClass.ts index 25eaaa872ea..44c1c22d5c8 100644 --- a/tests/cases/fourslash/completionListOnParamInClass.ts +++ b/tests/cases/fourslash/completionListOnParamInClass.ts @@ -5,5 +5,5 @@ ////} goTo.marker(); -verify.completionListContains('parseInt'); - +verify.not.completionListContains('parseInt'); +verify.completionListContains('encoder'); diff --git a/tests/cases/fourslash/completionListWithMeanings.ts b/tests/cases/fourslash/completionListWithMeanings.ts new file mode 100644 index 00000000000..995bec8bd66 --- /dev/null +++ b/tests/cases/fourslash/completionListWithMeanings.ts @@ -0,0 +1,68 @@ +/// + +////namespace m { export interface point2 { } } +////namespace m2 { export var zz = 10; } +////namespace m3 { export var zz2 = 10; export interface point3 { } } +////interface point { +//// x: number; +//// y: number; +////} +////var xx = 10; +////var tt = /*valueExpr*/xx; +////var yy: /*typeExpr*/point = { x: 4, y: 3 + /*valueExprInObjectLiteral*/tt }; +////var kk: m3.point3/*membertypeExpr*/ = m3.zz2/*membervalueExpr*/; + +const markers = test.markerNames(); + +function getVerifyBasedOnMarker(marker: string, meaning: string) { + return marker.indexOf(meaning) === 0 ? verify : verify.not; +} + +function verifyCompletions(verify: FourSlashInterface.verifyNegatable, completions: CompletionInfo[]) { + for (const info of completions) { + verify.completionListContains(info[0], info[1]); + } +} + +type CompletionInfo = [string, string]; +function verifyCompletionsExistForMeaning(marker: string, meaning: string, completions: CompletionInfo[]) { + verifyCompletions(getVerifyBasedOnMarker(marker, meaning), completions); +} + +function verifyCompletionsDoNotExistForMeaning(marker: string, meaning: string, completions: CompletionInfo[]) { + verifyCompletions(getVerifyBasedOnMarker(marker, meaning) === verify.not ? verify : verify.not, completions); +} + +const values: CompletionInfo[] = [ + ["xx", "var xx: number"], + ["tt", "var tt: number"], + ["yy", "var yy: point"], + ["m2", "namespace m2"], // With no type side, allowed only in value +]; + +const types: CompletionInfo[] = [ + ["point", "interface point"], + ["m", "namespace m"], // Uninstantiated namespace only allowed at type locations +]; + +const namespaces: CompletionInfo[] = [ + ["m3", "namespace m3"], // Has both type and values, allowed in all locations +]; + +const membervalues: CompletionInfo[] = [ + ["zz2", "var m3.zz2: number"], +]; + + +const membertypes: CompletionInfo[] = [ + ["point3", "interface m3.point3"], +]; + +for (const marker of markers) { + goTo.marker(marker); + verifyCompletionsExistForMeaning(marker, "value", values); + verifyCompletionsExistForMeaning(marker, "type", types); + verifyCompletionsExistForMeaning(marker, "membervalue", membervalues); + verifyCompletionsExistForMeaning(marker, "membertype", membertypes); + verifyCompletionsDoNotExistForMeaning(marker, "member", namespaces); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionListWithModulesFromModule.ts b/tests/cases/fourslash/completionListWithModulesFromModule.ts index 3a1f3daa29e..462faa5ebf5 100644 --- a/tests/cases/fourslash/completionListWithModulesFromModule.ts +++ b/tests/cases/fourslash/completionListWithModulesFromModule.ts @@ -191,6 +191,7 @@ //// sifn(shadow: any): any; //// } //// /*shadowNamespaceWithNoExport*/ +//// var tmp: /*shadowNamespaceWithNoExportType*/ ////} //// ////namespace mod4 { @@ -214,12 +215,14 @@ //// sifn(shadow: any): any; //// } //// /*shadowNamespaceWithExport*/ +//// var tmp: /*shadowNamespaceWithExportType*/ ////} //// ////namespace mod5 { //// import Mod1 = mod1; //// import iMod1 = mod1.mod1emod; //// /*namespaceWithImport*/ +//// var tmp: /*namespaceWithImportType*/ ////} //// ////function shwfn() { @@ -276,51 +279,87 @@ function goToMarkAndVerifyShadow() verify.not.completionListContains('mod2emod'); } +function getVerify(isTypeLocation?: boolean) { + return { + verifyValue: isTypeLocation ? verify.not : verify, + verifyType: isTypeLocation ? verify : verify.not, + verifyValueOrType: verify + }; +} + +function typeLocationVerify(valueMarker: string, verify: (typeMarker: string) => void) { + verify(valueMarker + "Type"); + return valueMarker; +} // from a shadow namespace with no export -goTo.marker('shadowNamespaceWithNoExport'); -verify.completionListContains('shwvar', 'var shwvar: string'); -verify.completionListContains('shwfn', 'function shwfn(shadow: any): void'); -verify.completionListContains('shwcls', 'class shwcls'); -verify.completionListContains('shwint', 'interface shwint'); -goToMarkAndVerifyShadow(); +verifyShadowNamespaceWithNoExport(); +function verifyShadowNamespaceWithNoExport(marker?: string) { + const { verifyValue, verifyType, verifyValueOrType } = getVerify(!!marker); + if (!marker) { + marker = typeLocationVerify('shadowNamespaceWithNoExport', verifyShadowNamespaceWithNoExport); + } + goTo.marker(marker); + + verifyValue.completionListContains('shwvar', 'var shwvar: string'); + verifyValue.completionListContains('shwfn', 'function shwfn(shadow: any): void'); + verifyValueOrType.completionListContains('shwcls', 'class shwcls'); + verifyType.completionListContains('shwint', 'interface shwint'); + + goToMarkAndVerifyShadow(); +} // from a shadow namespace with export -goTo.marker('shadowNamespaceWithExport'); -verify.completionListContains('shwvar', 'var mod4.shwvar: string'); -verify.completionListContains('shwfn', 'function mod4.shwfn(shadow: any): void'); -verify.completionListContains('shwcls', 'class mod4.shwcls'); -verify.completionListContains('shwint', 'interface mod4.shwint'); -goToMarkAndVerifyShadow(); +verifyShadowNamespaceWithNoExport(); +function verifyShadowNamespaceWithExport(marker?: string) { + const { verifyValue, verifyType, verifyValueOrType } = getVerify(!!marker); + if (!marker) { + marker = typeLocationVerify('shadowNamespaceWithExport', verifyShadowNamespaceWithExport); + } + goTo.marker(marker); + verifyValue.completionListContains('shwvar', 'var mod4.shwvar: string'); + verifyValue.completionListContains('shwfn', 'function mod4.shwfn(shadow: any): void'); + verifyValueOrType.completionListContains('shwcls', 'class mod4.shwcls'); + verifyType.completionListContains('shwint', 'interface mod4.shwint'); + goToMarkAndVerifyShadow(); +} // from a namespace with import -goTo.marker('namespaceWithImport'); -verify.completionListContains('mod1', 'namespace mod1'); -verify.completionListContains('mod2', 'namespace mod2'); -verify.completionListContains('mod3', 'namespace mod3'); -verify.completionListContains('shwvar', 'var shwvar: number'); -verify.completionListContains('shwfn', 'function shwfn(): void'); -verify.completionListContains('shwcls', 'class shwcls'); -verify.completionListContains('shwint', 'interface shwint'); +verifyShadowNamespaceWithNoExport(); +function verifyNamespaceWithImport(marker?: string) { + const { verifyValue, verifyType, verifyValueOrType } = getVerify(!!marker); + if (!marker) { + marker = typeLocationVerify('namespaceWithImport', verifyNamespaceWithImport); + } + goTo.marker(marker); -sharedNegativeVerify(); + verifyValue.completionListContains('mod1', 'namespace mod1'); + verifyValue.completionListContains('mod2', 'namespace mod2'); + verifyValue.completionListContains('mod3', 'namespace mod3'); + verifyValue.completionListContains('shwvar', 'var shwvar: number'); + verifyValue.completionListContains('shwfn', 'function shwfn(): void'); + verifyValueOrType.completionListContains('shwcls', 'class shwcls'); + verifyType.completionListContains('shwint', 'interface shwint'); -verify.not.completionListContains('mod1var'); -verify.not.completionListContains('mod1fn'); -verify.not.completionListContains('mod1cls'); -verify.not.completionListContains('mod1int'); -verify.not.completionListContains('mod1mod'); -verify.not.completionListContains('mod1evar'); -verify.not.completionListContains('mod1efn'); -verify.not.completionListContains('mod1ecls'); -verify.not.completionListContains('mod1eint'); -verify.not.completionListContains('mod1emod'); -verify.not.completionListContains('mX'); -verify.not.completionListContains('mFunc'); -verify.not.completionListContains('mClass'); -verify.not.completionListContains('mInt'); -verify.not.completionListContains('mMod'); -verify.not.completionListContains('meX'); -verify.not.completionListContains('meFunc'); -verify.not.completionListContains('meClass'); -verify.not.completionListContains('meInt'); -verify.not.completionListContains('meMod'); \ No newline at end of file + sharedNegativeVerify(); + + verify.not.completionListContains('mod1var'); + verify.not.completionListContains('mod1fn'); + verify.not.completionListContains('mod1cls'); + verify.not.completionListContains('mod1int'); + verify.not.completionListContains('mod1mod'); + verify.not.completionListContains('mod1evar'); + verify.not.completionListContains('mod1efn'); + verify.not.completionListContains('mod1ecls'); + verify.not.completionListContains('mod1eint'); + verify.not.completionListContains('mod1emod'); + verify.not.completionListContains('mX'); + verify.not.completionListContains('mFunc'); + verify.not.completionListContains('mClass'); + verify.not.completionListContains('mInt'); + verify.not.completionListContains('mMod'); + verify.not.completionListContains('meX'); + verify.not.completionListContains('meFunc'); + verify.not.completionListContains('meClass'); + verify.not.completionListContains('meInt'); + verify.not.completionListContains('meMod'); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts b/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts index 916ad10fe9c..5d950a5d620 100644 --- a/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts +++ b/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts @@ -62,6 +62,7 @@ //// namespace m1Mod { } //// export namespace m1eMod { } //// /*namespace*/ +//// var tmp: /*namespaceType*/ //// } //// export var mod1evar = 1; //// export function mod1efn() { @@ -124,8 +125,10 @@ //// namespace mMod { } //// export namespace meMod { } //// /*exportedNamespace*/ +//// var tmp: /*exportedNamespaceType*/ //// } //// /*mod1*/ +//// var tmp: /*mod1Type*/; ////} //// ////// EXTENDING NAMESPACE 1 @@ -133,6 +136,7 @@ //// export var mod1eexvar = 1; //// var mod1exvar = 2; //// /*extendedNamespace*/ +//// var tmp: /*extendedNamespaceType*/; ////} //// ////namespace mod2 { @@ -225,28 +229,46 @@ //// ////var shwvar = 1; -function goToMarkAndGeneralVerify(marker: string, isClassScope?: boolean) +interface GotoMarkVerifyOptions { + isClassScope?: boolean; + isTypeLocation?: boolean; +} + +function getVerify(isTypeLocation: boolean) { + return { + verifyValue: isTypeLocation ? verify.not : verify, + verifyType: isTypeLocation ? verify : verify.not, + verifyValueOrType: verify, + verifyNotValueOrType: verify.not, + }; +} + +function goToMarkAndGeneralVerify(marker: string, { isClassScope, isTypeLocation }: GotoMarkVerifyOptions = {}) { goTo.marker(marker); - const verifyModule = isClassScope ? verify.not : verify; - verifyModule.completionListContains('mod1var', 'var mod1var: number'); - verifyModule.completionListContains('mod1fn', 'function mod1fn(): void'); - verifyModule.completionListContains('mod1cls', 'class mod1cls'); - verifyModule.completionListContains('mod1int', 'interface mod1int'); - verifyModule.completionListContains('mod1mod', 'namespace mod1mod'); - verifyModule.completionListContains('mod1evar', 'var mod1.mod1evar: number'); - verifyModule.completionListContains('mod1efn', 'function mod1.mod1efn(): void'); - verifyModule.completionListContains('mod1ecls', 'class mod1.mod1ecls'); - verifyModule.completionListContains('mod1eint', 'interface mod1.mod1eint'); - verifyModule.completionListContains('mod1emod', 'namespace mod1.mod1emod'); - verifyModule.completionListContains('mod1eexvar', 'var mod1.mod1eexvar: number'); - verifyModule.completionListContains('mod2', 'namespace mod2'); - verifyModule.completionListContains('mod3', 'namespace mod3'); - verifyModule.completionListContains('shwvar', 'var shwvar: number'); - verifyModule.completionListContains('shwfn', 'function shwfn(): void'); - verifyModule.completionListContains('shwcls', 'class shwcls'); - verifyModule.completionListContains('shwint', 'interface shwint'); + const verifyValueInModule = isClassScope || isTypeLocation ? verify.not : verify; + const verifyValueOrTypeInModule = isClassScope ? verify.not : verify; + const verifyTypeInModule = isTypeLocation ? verify : verify.not; + verifyValueInModule.completionListContains('mod1var', 'var mod1var: number'); + verifyValueInModule.completionListContains('mod1fn', 'function mod1fn(): void'); + verifyValueInModule.completionListContains('mod1evar', 'var mod1.mod1evar: number'); + verifyValueInModule.completionListContains('mod1efn', 'function mod1.mod1efn(): void'); + verifyValueInModule.completionListContains('mod1eexvar', 'var mod1.mod1eexvar: number'); + verifyValueInModule.completionListContains('mod3', 'namespace mod3'); + verifyValueInModule.completionListContains('shwvar', 'var shwvar: number'); + verifyValueInModule.completionListContains('shwfn', 'function shwfn(): void'); + + verifyTypeInModule.completionListContains('mod1int', 'interface mod1int'); + verifyTypeInModule.completionListContains('mod1eint', 'interface mod1.mod1eint'); + verifyTypeInModule.completionListContains('shwint', 'interface shwint'); + + verifyValueOrTypeInModule.completionListContains('mod1cls', 'class mod1cls'); + verifyValueOrTypeInModule.completionListContains('mod1mod', 'namespace mod1mod'); + verifyValueOrTypeInModule.completionListContains('mod1ecls', 'class mod1.mod1ecls'); + verifyValueOrTypeInModule.completionListContains('mod1emod', 'namespace mod1.mod1emod'); + verifyValueOrTypeInModule.completionListContains('mod2', 'namespace mod2'); + verifyValueOrTypeInModule.completionListContains('shwcls', 'class shwcls'); verify.not.completionListContains('mod2var'); verify.not.completionListContains('mod2fn'); @@ -274,6 +296,8 @@ function goToMarkAndGeneralVerify(marker: string, isClassScope?: boolean) // from mod1 goToMarkAndGeneralVerify('mod1'); +// from mod1 in type position +goToMarkAndGeneralVerify('mod1Type', { isTypeLocation: true }); // from function in mod1 goToMarkAndGeneralVerify('function'); @@ -281,7 +305,7 @@ verify.completionListContains('bar', '(local var) bar: number'); verify.completionListContains('foob', '(local function) foob(): void'); // from class in mod1 -goToMarkAndGeneralVerify('class', /*isClassScope*/ true); +goToMarkAndGeneralVerify('class', { isClassScope: true }); //verify.not.completionListContains('ceFunc'); //verify.not.completionListContains('ceVar'); @@ -289,17 +313,28 @@ goToMarkAndGeneralVerify('class', /*isClassScope*/ true); goToMarkAndGeneralVerify('interface'); // from namespace in mod1 -goToMarkAndGeneralVerify('namespace'); -verify.completionListContains('m1X', 'var m1X: number'); -verify.completionListContains('m1Func', 'function m1Func(): void'); -verify.completionListContains('m1Class', 'class m1Class'); -verify.completionListContains('m1Int', 'interface m1Int'); -verify.completionListContains('m1Mod', 'namespace m1Mod'); -verify.completionListContains('m1eX', 'var mod1mod.m1eX: number'); -verify.completionListContains('m1eFunc', 'function mod1mod.m1eFunc(): void'); -verify.completionListContains('m1eClass', 'class mod1mod.m1eClass'); -verify.completionListContains('m1eInt', 'interface mod1mod.m1eInt'); -verify.completionListContains('m1eMod', 'namespace mod1mod.m1eMod'); +verifyNamespaceInMod1('namespace'); +verifyNamespaceInMod1('namespaceType', /*isTypeLocation*/ true); + +function verifyNamespaceInMod1(marker: string, isTypeLocation?: boolean) { + goToMarkAndGeneralVerify(marker, { isTypeLocation }); + + const { verifyValue, verifyType, verifyValueOrType, verifyNotValueOrType } = getVerify(isTypeLocation); + + verifyValue.completionListContains('m1X', 'var m1X: number'); + verifyValue.completionListContains('m1Func', 'function m1Func(): void'); + verifyValue.completionListContains('m1eX', 'var mod1mod.m1eX: number'); + verifyValue.completionListContains('m1eFunc', 'function mod1mod.m1eFunc(): void'); + + verifyType.completionListContains('m1Int', 'interface m1Int'); + verifyType.completionListContains('m1eInt', 'interface mod1mod.m1eInt'); + + verifyValueOrType.completionListContains('m1Class', 'class m1Class'); + verifyValueOrType.completionListContains('m1eClass', 'class mod1mod.m1eClass'); + + verifyNotValueOrType.completionListContains('m1Mod', 'namespace m1Mod'); + verifyNotValueOrType.completionListContains('m1eMod', 'namespace mod1mod.m1eMod'); +} // from exported function in mod1 goToMarkAndGeneralVerify('exportedFunction'); @@ -307,59 +342,77 @@ verify.completionListContains('bar', '(local var) bar: number'); verify.completionListContains('foob', '(local function) foob(): void'); // from exported class in mod1 -goToMarkAndGeneralVerify('exportedClass', /*isClassScope*/ true); -//verify.not.completionListContains('ceFunc'); -//verify.not.completionListContains('ceVar'); +goToMarkAndGeneralVerify('exportedClass', { isClassScope: true }); +verify.not.completionListContains('ceFunc'); +verify.not.completionListContains('ceVar'); // from exported interface in mod1 goToMarkAndGeneralVerify('exportedInterface'); // from exported namespace in mod1 -goToMarkAndGeneralVerify('exportedNamespace'); -verify.completionListContains('mX', 'var mX: number'); -verify.completionListContains('mFunc', 'function mFunc(): void'); -verify.completionListContains('mClass', 'class mClass'); -verify.completionListContains('mInt', 'interface mInt'); -verify.completionListContains('mMod', 'namespace mMod'); -verify.completionListContains('meX', 'var mod1.mod1emod.meX: number'); -verify.completionListContains('meFunc', 'function mod1.mod1emod.meFunc(): void'); -verify.completionListContains('meClass', 'class mod1.mod1emod.meClass'); -verify.completionListContains('meInt', 'interface mod1.mod1emod.meInt'); -verify.completionListContains('meMod', 'namespace mod1.mod1emod.meMod'); +verifyExportedNamespace('exportedNamespace'); +verifyExportedNamespace('exportedNamespaceType', /*isTypeLocation*/ true); +function verifyExportedNamespace(marker: string, isTypeLocation?: boolean) { + goToMarkAndGeneralVerify(marker, { isTypeLocation }); + const { verifyValue, verifyType, verifyValueOrType, verifyNotValueOrType } = getVerify(isTypeLocation); + verifyValue.completionListContains('mX', 'var mX: number'); + verifyValue.completionListContains('mFunc', 'function mFunc(): void'); + verifyValue.completionListContains('meX', 'var mod1.mod1emod.meX: number'); + verifyValue.completionListContains('meFunc', 'function mod1.mod1emod.meFunc(): void'); + + verifyType.completionListContains('mInt', 'interface mInt'); + verifyType.completionListContains('meInt', 'interface mod1.mod1emod.meInt'); + + verifyValueOrType.completionListContains('mClass', 'class mClass'); + verifyValueOrType.completionListContains('meClass', 'class mod1.mod1emod.meClass'); + + verifyNotValueOrType.completionListContains('mMod', 'namespace mMod'); + verifyNotValueOrType.completionListContains('meMod', 'namespace mod1.mod1emod.meMod'); +} // from extended namespace -goTo.marker('extendedNamespace'); -verify.completionListContains('mod1evar', 'var mod1.mod1evar: number'); -verify.completionListContains('mod1efn', 'function mod1.mod1efn(): void'); -verify.completionListContains('mod1ecls', 'class mod1.mod1ecls'); -verify.completionListContains('mod1eint', 'interface mod1.mod1eint'); -verify.completionListContains('mod1emod', 'namespace mod1.mod1emod'); -verify.completionListContains('mod1eexvar', 'var mod1.mod1eexvar: number'); -verify.completionListContains('mod2', 'namespace mod2'); -verify.completionListContains('mod3', 'namespace mod3'); -verify.completionListContains('shwvar', 'var shwvar: number'); -verify.completionListContains('shwfn', 'function shwfn(): void'); -verify.completionListContains('shwcls', 'class shwcls'); -verify.completionListContains('shwint', 'interface shwint'); +verifyExtendedNamespace('extendedNamespace'); +verifyExtendedNamespace('extendedNamespaceType', /*isTypeLocation*/ true); -verify.not.completionListContains('mod2var'); -verify.not.completionListContains('mod2fn'); -verify.not.completionListContains('mod2cls'); -verify.not.completionListContains('mod2int'); -verify.not.completionListContains('mod2mod'); -verify.not.completionListContains('mod2evar'); -verify.not.completionListContains('mod2efn'); -verify.not.completionListContains('mod2ecls'); -verify.not.completionListContains('mod2eint'); -verify.not.completionListContains('mod2emod'); -verify.not.completionListContains('sfvar'); -verify.not.completionListContains('sffn'); -verify.not.completionListContains('scvar'); -verify.not.completionListContains('scfn'); -verify.not.completionListContains('scpfn'); -verify.not.completionListContains('scpvar'); -verify.not.completionListContains('scsvar'); -verify.not.completionListContains('scsfn'); -verify.not.completionListContains('sivar'); -verify.not.completionListContains('sifn'); -verify.not.completionListContains('mod2eexvar'); \ No newline at end of file +function verifyExtendedNamespace(marker: string, isTypeLocation?: boolean) { + goTo.marker(marker); + const { verifyValue, verifyType, verifyValueOrType, verifyNotValueOrType } = getVerify(isTypeLocation); + + verifyValue.completionListContains('mod1evar', 'var mod1.mod1evar: number'); + verifyValue.completionListContains('mod1efn', 'function mod1.mod1efn(): void'); + verifyValue.completionListContains('mod1eexvar', 'var mod1.mod1eexvar: number'); + verifyValue.completionListContains('mod3', 'namespace mod3'); + verifyValue.completionListContains('shwvar', 'var shwvar: number'); + verifyValue.completionListContains('shwfn', 'function shwfn(): void'); + + verifyType.completionListContains('mod1eint', 'interface mod1.mod1eint'); + verifyType.completionListContains('shwint', 'interface shwint'); + + verifyValueOrType.completionListContains('mod1ecls', 'class mod1.mod1ecls'); + verifyValueOrType.completionListContains('mod1emod', 'namespace mod1.mod1emod'); + verifyValueOrType.completionListContains('mod2', 'namespace mod2'); + verifyValueOrType.completionListContains('shwcls', 'class shwcls'); + + + verify.not.completionListContains('mod2var'); + verify.not.completionListContains('mod2fn'); + verify.not.completionListContains('mod2cls'); + verify.not.completionListContains('mod2int'); + verify.not.completionListContains('mod2mod'); + verify.not.completionListContains('mod2evar'); + verify.not.completionListContains('mod2efn'); + verify.not.completionListContains('mod2ecls'); + verify.not.completionListContains('mod2eint'); + verify.not.completionListContains('mod2emod'); + verify.not.completionListContains('sfvar'); + verify.not.completionListContains('sffn'); + verify.not.completionListContains('scvar'); + verify.not.completionListContains('scfn'); + verify.not.completionListContains('scpfn'); + verify.not.completionListContains('scpvar'); + verify.not.completionListContains('scsvar'); + verify.not.completionListContains('scsfn'); + verify.not.completionListContains('sivar'); + verify.not.completionListContains('sifn'); + verify.not.completionListContains('mod2eexvar'); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts b/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts index d6c44f4b7eb..c72159b0027 100644 --- a/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts +++ b/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts @@ -266,7 +266,7 @@ verify.completionListContains('mod3', 'namespace mod3'); verify.completionListContains('shwvar', 'var shwvar: number'); verify.completionListContains('shwfn', 'function shwfn(): void'); verify.completionListContains('shwcls', 'class shwcls'); -verify.completionListContains('shwint', 'interface shwint'); +verify.not.completionListContains('shwint', 'interface shwint'); verifyNotContainFunctionMembers(); verifyNotContainClassMembers(); diff --git a/tests/cases/fourslash/completionListWithModulesOutsideModuleScope2.ts b/tests/cases/fourslash/completionListWithModulesOutsideModuleScope2.ts index 340d0bd3191..c8aa1933def 100644 --- a/tests/cases/fourslash/completionListWithModulesOutsideModuleScope2.ts +++ b/tests/cases/fourslash/completionListWithModulesOutsideModuleScope2.ts @@ -274,7 +274,7 @@ function goToMarkerAndVerify(marker: string) verify.completionListContains('shwvar', 'var shwvar: number'); verify.completionListContains('shwfn', 'function shwfn(): void'); verify.completionListContains('shwcls', 'class shwcls'); - verify.completionListContains('shwint', 'interface shwint'); + verify.not.completionListContains('shwint', 'interface shwint'); verify.not.completionListContains('mod2var'); verify.not.completionListContains('mod2fn'); diff --git a/tests/cases/fourslash/completionWithNamespaceInsideFunction.ts b/tests/cases/fourslash/completionWithNamespaceInsideFunction.ts index fb537bca71a..f9259dd2eed 100644 --- a/tests/cases/fourslash/completionWithNamespaceInsideFunction.ts +++ b/tests/cases/fourslash/completionWithNamespaceInsideFunction.ts @@ -10,15 +10,37 @@ //// /*2*/ ////} /////*3*/ +////function f2() { +//// namespace n2 { +//// class I2 { +//// x: number +//// } +//// /*11*/ +//// } +//// /*22*/ +////} +/////*33*/ goTo.marker('1'); verify.completionListContains("f", "function f(): void"); -verify.completionListContains("n", "namespace n"); -verify.completionListContains("I", "interface I"); +verify.not.completionListContains("n", "namespace n"); +verify.not.completionListContains("I", "interface I"); goTo.marker('2'); verify.completionListContains("f", "function f(): void"); -verify.completionListContains("n", "namespace n"); +verify.not.completionListContains("n", "namespace n"); goTo.marker('3'); -verify.completionListContains("f", "function f(): void"); \ No newline at end of file +verify.completionListContains("f", "function f(): void"); + +goTo.marker('11'); +verify.completionListContains("f2", "function f2(): void"); +verify.completionListContains("n2", "namespace n2"); +verify.completionListContains("I2", "class I2"); + +goTo.marker('22'); +verify.completionListContains("f2", "function f2(): void"); +verify.completionListContains("n2", "namespace n2"); + +goTo.marker('33'); +verify.completionListContains("f2", "function f2(): void"); \ No newline at end of file diff --git a/tests/cases/fourslash/externalModuleWithExportAssignment.ts b/tests/cases/fourslash/externalModuleWithExportAssignment.ts index 2c68934e49e..90009fe9d46 100644 --- a/tests/cases/fourslash/externalModuleWithExportAssignment.ts +++ b/tests/cases/fourslash/externalModuleWithExportAssignment.ts @@ -56,8 +56,8 @@ goTo.marker('9'); verify.quickInfoIs("(property) test1: a1.connectModule(res: any, req: any, next: any) => void", undefined); verify.completionListContains("test1", "(property) test1: a1.connectModule(res: any, req: any, next: any) => void", undefined); verify.completionListContains("test2", "(method) test2(): a1.connectModule", undefined); -verify.completionListContains("connectModule"); -verify.completionListContains("connectExport"); +verify.not.completionListContains("connectModule"); +verify.not.completionListContains("connectExport"); goTo.marker('10'); verify.currentSignatureHelpIs("test1(res: any, req: any, next: any): void"); diff --git a/tests/cases/fourslash/memberListOfModule.ts b/tests/cases/fourslash/memberListOfModule.ts index 4724691c0a7..0e095c94cbd 100644 --- a/tests/cases/fourslash/memberListOfModule.ts +++ b/tests/cases/fourslash/memberListOfModule.ts @@ -14,6 +14,6 @@ ////var x: Foo./**/ goTo.marker(); -verify.completionListCount(2); +verify.completionListCount(1); verify.completionListContains('Bar'); -verify.completionListContains('Blah'); \ No newline at end of file +verify.not.completionListContains('Blah'); \ No newline at end of file From 3acc76cc8faf045a3de26ca19c6ee656d83dda70 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 1 Jun 2017 12:11:09 -0700 Subject: [PATCH 003/138] Allow JS constructor function to return non-void --- src/compiler/checker.ts | 2 +- .../reference/jsConstructorFunction.symbols | 56 +++++++++++++ .../reference/jsConstructorFunction.types | 81 +++++++++++++++++++ tests/cases/compiler/jsConstructorFunction.ts | 22 +++++ 4 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsConstructorFunction.symbols create mode 100644 tests/baselines/reference/jsConstructorFunction.types create mode 100644 tests/cases/compiler/jsConstructorFunction.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cfe2c5a6bf2..a3f8b9facad 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15835,7 +15835,7 @@ namespace ts { const callSignatures = getSignaturesOfType(expressionType, SignatureKind.Call); if (callSignatures.length) { const signature = resolveCall(node, callSignatures, candidatesOutArray); - if (getReturnTypeOfSignature(signature) !== voidType) { + if (!isInJavaScriptFile(signature.declaration) && getReturnTypeOfSignature(signature) !== voidType) { error(node, Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } if (getThisTypeOfSignature(signature) === voidType) { diff --git a/tests/baselines/reference/jsConstructorFunction.symbols b/tests/baselines/reference/jsConstructorFunction.symbols new file mode 100644 index 00000000000..d4954b1abdc --- /dev/null +++ b/tests/baselines/reference/jsConstructorFunction.symbols @@ -0,0 +1,56 @@ +=== tests/cases/compiler/index.js === +var Person = function (firstNameOrPojo, lastName) { +>Person : Symbol(Person, Decl(index.js, 0, 3)) +>firstNameOrPojo : Symbol(firstNameOrPojo, Decl(index.js, 0, 23)) +>lastName : Symbol(lastName, Decl(index.js, 0, 39)) + + if (typeof firstNameOrPojo === "string") { +>firstNameOrPojo : Symbol(firstNameOrPojo, Decl(index.js, 0, 23)) + + this.firstName = firstNameOrPojo; +>firstName : Symbol(Person.firstName, Decl(index.js, 2, 46)) +>firstNameOrPojo : Symbol(firstNameOrPojo, Decl(index.js, 0, 23)) + + this.lastName = lastName; +>lastName : Symbol(Person.lastName, Decl(index.js, 3, 41)) +>lastName : Symbol(lastName, Decl(index.js, 0, 39)) + + } else { + return new Person(firstNameOrPojo.firstName, firstNameOrPojo.lastName); +>Person : Symbol(Person, Decl(index.js, 0, 3)) +>firstNameOrPojo : Symbol(firstNameOrPojo, Decl(index.js, 0, 23)) +>firstNameOrPojo : Symbol(firstNameOrPojo, Decl(index.js, 0, 23)) + } +}; + +Person.prototype.greet = function greet() { +>Person.prototype : Symbol(Person.greet, Decl(index.js, 8, 2)) +>Person : Symbol(Person, Decl(index.js, 0, 3)) +>prototype : Symbol(Function.prototype, Decl(lib.es5.d.ts, --, --)) +>greet : Symbol(Person.greet, Decl(index.js, 8, 2)) +>greet : Symbol(greet, Decl(index.js, 10, 24)) + + return `Hello, I am ${this.firstName} ${this.lastName}.`; +>this.firstName : Symbol(Person.firstName, Decl(index.js, 2, 46)) +>this : Symbol(Person, Decl(index.js, 0, 12)) +>firstName : Symbol(Person.firstName, Decl(index.js, 2, 46)) +>this.lastName : Symbol(Person.lastName, Decl(index.js, 3, 41)) +>this : Symbol(Person, Decl(index.js, 0, 12)) +>lastName : Symbol(Person.lastName, Decl(index.js, 3, 41)) + +}; + +var fred = new Person({ firstName: "Fred", lastName: "Flintstone" }); +>fred : Symbol(fred, Decl(index.js, 14, 3)) +>Person : Symbol(Person, Decl(index.js, 0, 3)) +>firstName : Symbol(firstName, Decl(index.js, 14, 23)) +>lastName : Symbol(lastName, Decl(index.js, 14, 42)) + +console.log(fred.greet()); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>fred.greet : Symbol(Person.greet, Decl(index.js, 8, 2)) +>fred : Symbol(fred, Decl(index.js, 14, 3)) +>greet : Symbol(Person.greet, Decl(index.js, 8, 2)) + diff --git a/tests/baselines/reference/jsConstructorFunction.types b/tests/baselines/reference/jsConstructorFunction.types new file mode 100644 index 00000000000..3c2854ac87f --- /dev/null +++ b/tests/baselines/reference/jsConstructorFunction.types @@ -0,0 +1,81 @@ +=== tests/cases/compiler/index.js === +var Person = function (firstNameOrPojo, lastName) { +>Person : (firstNameOrPojo: any, lastName: any) => any +>function (firstNameOrPojo, lastName) { if (typeof firstNameOrPojo === "string") { this.firstName = firstNameOrPojo; this.lastName = lastName; } else { return new Person(firstNameOrPojo.firstName, firstNameOrPojo.lastName); }} : (firstNameOrPojo: any, lastName: any) => any +>firstNameOrPojo : any +>lastName : any + + if (typeof firstNameOrPojo === "string") { +>typeof firstNameOrPojo === "string" : boolean +>typeof firstNameOrPojo : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function" +>firstNameOrPojo : any +>"string" : "string" + + this.firstName = firstNameOrPojo; +>this.firstName = firstNameOrPojo : string +>this.firstName : any +>this : any +>firstName : any +>firstNameOrPojo : string + + this.lastName = lastName; +>this.lastName = lastName : any +>this.lastName : any +>this : any +>lastName : any +>lastName : any + + } else { + return new Person(firstNameOrPojo.firstName, firstNameOrPojo.lastName); +>new Person(firstNameOrPojo.firstName, firstNameOrPojo.lastName) : { firstName: string; lastName: any; greet: () => string; } +>Person : (firstNameOrPojo: any, lastName: any) => any +>firstNameOrPojo.firstName : any +>firstNameOrPojo : any +>firstName : any +>firstNameOrPojo.lastName : any +>firstNameOrPojo : any +>lastName : any + } +}; + +Person.prototype.greet = function greet() { +>Person.prototype.greet = function greet() { return `Hello, I am ${this.firstName} ${this.lastName}.`;} : () => string +>Person.prototype.greet : any +>Person.prototype : any +>Person : (firstNameOrPojo: any, lastName: any) => any +>prototype : any +>greet : any +>function greet() { return `Hello, I am ${this.firstName} ${this.lastName}.`;} : () => string +>greet : () => string + + return `Hello, I am ${this.firstName} ${this.lastName}.`; +>`Hello, I am ${this.firstName} ${this.lastName}.` : string +>this.firstName : string +>this : { firstName: string; lastName: any; greet: () => string; } +>firstName : string +>this.lastName : any +>this : { firstName: string; lastName: any; greet: () => string; } +>lastName : any + +}; + +var fred = new Person({ firstName: "Fred", lastName: "Flintstone" }); +>fred : { firstName: string; lastName: any; greet: () => string; } +>new Person({ firstName: "Fred", lastName: "Flintstone" }) : { firstName: string; lastName: any; greet: () => string; } +>Person : (firstNameOrPojo: any, lastName: any) => any +>{ firstName: "Fred", lastName: "Flintstone" } : { firstName: string; lastName: string; } +>firstName : string +>"Fred" : "Fred" +>lastName : string +>"Flintstone" : "Flintstone" + +console.log(fred.greet()); +>console.log(fred.greet()) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>fred.greet() : string +>fred.greet : () => string +>fred : { firstName: string; lastName: any; greet: () => string; } +>greet : () => string + diff --git a/tests/cases/compiler/jsConstructorFunction.ts b/tests/cases/compiler/jsConstructorFunction.ts new file mode 100644 index 00000000000..2cb0d16b766 --- /dev/null +++ b/tests/cases/compiler/jsConstructorFunction.ts @@ -0,0 +1,22 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @filename: index.js +// @lib: es5, dom +var Person = function (firstNameOrPojo, lastName) { + + if (typeof firstNameOrPojo === "string") { + this.firstName = firstNameOrPojo; + this.lastName = lastName; + } else { + return new Person(firstNameOrPojo.firstName, firstNameOrPojo.lastName); + } +}; + +Person.prototype.greet = function greet() { + return `Hello, I am ${this.firstName} ${this.lastName}.`; +}; + +var fred = new Person({ firstName: "Fred", lastName: "Flintstone" }); + +console.log(fred.greet()); \ No newline at end of file From ee5d1d33c1548d38165a3cf62dc938e928627fea Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 1 Jun 2017 16:20:30 -0700 Subject: [PATCH 004/138] Completion list in the type expression should show types --- src/harness/fourslash.ts | 7 +- src/services/completions.ts | 58 +++++--- src/services/utilities.ts | 4 +- ...JsdocTypedefTagTypeExpressionCompletion.ts | 70 +++++++++ ...sdocTypedefTagTypeExpressionCompletion2.ts | 65 ++++++++ ...sdocTypedefTagTypeExpressionCompletion3.ts | 127 ++++++++++++++++ ...jsdocTypedefTagTypeExpressionCompletion.ts | 140 ++++++++++++++++++ 7 files changed, 446 insertions(+), 25 deletions(-) create mode 100644 tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts create mode 100644 tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts create mode 100644 tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion3.ts create mode 100644 tests/cases/fourslash/jsdocTypedefTagTypeExpressionCompletion.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 8f19b83c7ad..0f840421b65 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -822,8 +822,8 @@ namespace FourSlash { function filterByTextOrDocumentation(entry: ts.CompletionEntry) { const details = that.getCompletionEntryDetails(entry.name); - const documentation = ts.displayPartsToString(details.documentation); - const text = ts.displayPartsToString(details.displayParts); + const documentation = details && ts.displayPartsToString(details.documentation); + const text = details && ts.displayPartsToString(details.displayParts); // If any of the expected values are undefined, assume that users don't // care about them. @@ -860,6 +860,9 @@ namespace FourSlash { if (expectedKind) { error += "Expected kind: " + expectedKind + " to equal: " + filterCompletions[0].kind + "."; } + else { + error += "kind: " + filterCompletions[0].kind + "."; + } if (replacementSpan) { const spanText = filterCompletions[0].replacementSpan ? stringify(filterCompletions[0].replacementSpan) : undefined; error += "Expected replacement span: " + stringify(replacementSpan) + " to equal: " + spanText + "."; diff --git a/src/services/completions.ts b/src/services/completions.ts index 94935d3f3db..7c0662c7531 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -354,7 +354,7 @@ namespace ts.Completions { let requestJsDocTag = false; let start = timestamp(); - const currentToken = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false); // TODO: GH#15853 + let currentToken = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false); // TODO: GH#15853 log("getCompletionData: Get current token: " + (timestamp() - start)); start = timestamp(); @@ -362,6 +362,7 @@ namespace ts.Completions { const insideComment = isInComment(sourceFile, position, currentToken); log("getCompletionData: Is inside comment: " + (timestamp() - start)); + let insideJsDocTagTypeExpression = false; if (insideComment) { if (hasDocComment(sourceFile, position)) { // The current position is next to the '@' sign, when no tag name being provided yet. @@ -394,22 +395,20 @@ namespace ts.Completions { // Completion should work inside certain JsDoc tags. For example: // /** @type {number | string} */ // Completion should work in the brackets - let insideJsDocTagExpression = false; const tag = getJsDocTagAtPosition(sourceFile, position); if (tag) { if (tag.tagName.pos <= position && position <= tag.tagName.end) { requestJsDocTagName = true; } - - switch (tag.kind) { - case SyntaxKind.JSDocTypeTag: - case SyntaxKind.JSDocParameterTag: - case SyntaxKind.JSDocReturnTag: - const tagWithExpression = tag; - if (tagWithExpression.typeExpression) { - insideJsDocTagExpression = tagWithExpression.typeExpression.pos < position && position < tagWithExpression.typeExpression.end; - } - break; + if (isTagWithTypeExpression(tag) && tag.typeExpression) { + currentToken = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ true); + if (!currentToken || + (!isDeclarationName(currentToken) && + (currentToken.parent.kind !== SyntaxKind.JSDocPropertyTag || + (currentToken.parent).name !== currentToken))) { + // Use as type location if inside tag's type expression + insideJsDocTagTypeExpression = isCurrentlyEditingNode(tag.typeExpression); + } } } @@ -417,7 +416,7 @@ namespace ts.Completions { return { symbols: undefined, isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, location: undefined, isRightOfDot: false, requestJsDocTagName, requestJsDocTag, hasFilteredClassMemberKeywords: false }; } - if (!insideJsDocTagExpression) { + if (!insideJsDocTagTypeExpression) { // Proceed if the current position is in jsDoc tag expression; otherwise it is a normal // comment or the plain text part of a jsDoc comment, so no completion should be available log("Returning an empty list because completion was inside a regular comment or plain text part of a JsDoc comment."); @@ -426,7 +425,7 @@ namespace ts.Completions { } start = timestamp(); - const previousToken = findPrecedingToken(position, sourceFile); + const previousToken = findPrecedingToken(position, sourceFile, /*startNode*/ undefined, insideJsDocTagTypeExpression); log("getCompletionData: Get previous token 1: " + (timestamp() - start)); // The decision to provide completion depends on the contextToken, which is determined through the previousToken. @@ -437,7 +436,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, insideJsDocTagTypeExpression); log("getCompletionData: Get previous token 2: " + (timestamp() - start)); } @@ -449,7 +448,7 @@ namespace ts.Completions { let isRightOfOpenTag = false; let isStartingCloseTag = false; - let location = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ false); // TODO: GH#15853 + let location = getTouchingPropertyName(sourceFile, position, insideJsDocTagTypeExpression); // TODO: GH#15853 if (contextToken) { // Bail out if this is a known invalid completion location if (isCompletionListBlocker(contextToken)) { @@ -553,6 +552,20 @@ namespace ts.Completions { return { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot: (isRightOfDot || isRightOfOpenTag), requestJsDocTagName, requestJsDocTag, hasFilteredClassMemberKeywords }; + type JSDocTagWithTypeExpression = JSDocAugmentsTag | JSDocParameterTag | JSDocPropertyTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag; + + function isTagWithTypeExpression(tag: JSDocTag): tag is JSDocTagWithTypeExpression { + switch (tag.kind) { + case SyntaxKind.JSDocAugmentsTag: + case SyntaxKind.JSDocParameterTag: + case SyntaxKind.JSDocPropertyTag: + case SyntaxKind.JSDocReturnTag: + case SyntaxKind.JSDocTypeTag: + case SyntaxKind.JSDocTypedefTag: + return true; + } + } + function getTypeScriptMemberSymbols(): void { // Right of dot member completion list isGlobalCompletion = false; @@ -560,7 +573,7 @@ namespace ts.Completions { isNewIdentifierLocation = false; // Since this is qualified name check its a type node location - const isTypeLocation = isPartOfTypeNode(node.parent); + const isTypeLocation = isPartOfTypeNode(node.parent) || insideJsDocTagTypeExpression; const isRhsOfImportDeclaration = isInRightSideOfInternalImportEqualsDeclaration(node); if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression) { let symbol = typeChecker.getSymbolAtLocation(node); @@ -722,8 +735,9 @@ namespace ts.Completions { return !!(symbol.flags & SymbolFlags.Namespace); } - if (!isContextTokenValueLocation(contextToken) && - (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken))) { + if (insideJsDocTagTypeExpression || + (!isContextTokenValueLocation(contextToken) && + (isPartOfTypeNode(location) || isContextTokenTypeLocation(contextToken)))) { // Its a type, but you can reach it by namespace.type as well return symbolCanbeReferencedAtTypeLocation(symbol); } @@ -770,14 +784,16 @@ namespace ts.Completions { symbol = typeChecker.getAliasedSymbol(symbol); } + if (symbol.flags & SymbolFlags.Type) { + return true; + } + if (symbol.flags & (SymbolFlags.ValueModule | SymbolFlags.NamespaceModule)) { const exportedSymbols = typeChecker.getExportsOfModule(symbol); // If the exported symbols contains type, // symbol can be referenced at locations where type is allowed return forEach(exportedSymbols, symbolCanbeReferencedAtTypeLocation); } - - return !!(symbol.flags & (SymbolFlags.NamespaceModule | SymbolFlags.Type)); } /** diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 7fd3d837406..d40824ced33 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -707,7 +707,7 @@ namespace ts { } } - export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node): Node { + export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, includeJsDocComment?: boolean): Node { return find(startNode || sourceFile); function findRightmostToken(n: Node): Node { @@ -738,7 +738,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 = child.getStart(sourceFile, includeJsDocComment); const lookInPreviousChild = (start >= position) || // cursor in the leading trivia (child.kind === SyntaxKind.JsxText && start === child.end); // whitespace only JsxText diff --git a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts new file mode 100644 index 00000000000..62046458e4c --- /dev/null +++ b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts @@ -0,0 +1,70 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsFileJsdocTypedefTagTypeExpressionCompletion_typedef.js + +//// /** +//// * @typedef {/*1*/string | /*2*/number} T.NumberLike +//// * @typedef {{/*propertyName*/age: /*3*/number}} T.People +//// * @typedef {string | number} T.O.Q.NumberLike +//// * @type {/*4*/T./*1TypeMember*/NumberLike} +//// */ +//// var x; +//// /** @type {/*5*/T./*2TypeMember*/O.Q.NumberLike} */ +//// var x1; +//// /** @type {/*6*/T./*3TypeMember*/People} */ +//// var x1; +//// /*globalValue*/ + +interface VeriferCompletionsInJsDoc { + verifyType(symbol: string, kind: string): void; + verifyValue(symbol: string, kind: string): void; + verifyTypeMember(symbol: string, kind: string): void; +} + +function verifyCompletionsInJsDocType(marker: string, { verifyType, verifyValue, verifyTypeMember }: VeriferCompletionsInJsDoc) { + goTo.marker(marker); + + verifyType("T", "module"); + + // TODO: May be filter keywords based on context + //verifyType("string", "keyword"); + //verifyType("number", "keyword"); + + verifyValue("x", "var"); + verifyValue("x1", "var"); + + verifyTypeMember("NumberLike", "type"); + verifyTypeMember("People", "type"); + verifyTypeMember("O", "module"); +} + +function verifySymbolPresentWithKind(symbol: string, kind: string) { + return verify.completionListContains(symbol, /*text*/ undefined, /*documentation*/ undefined, kind); +} + +function verifySymbolPresentWithWarning(symbol: string) { + return verifySymbolPresentWithKind(symbol, "warning"); +} + +for (let i = 1; i <= 6; i++) { + verifyCompletionsInJsDocType(i.toString(), { + verifyType: verifySymbolPresentWithKind, + verifyValue: verifySymbolPresentWithWarning, + verifyTypeMember: verifySymbolPresentWithWarning, + }); +} +verifyCompletionsInJsDocType("globalValue", { + verifyType: verifySymbolPresentWithWarning, + verifyValue: verifySymbolPresentWithKind, + verifyTypeMember: verifySymbolPresentWithWarning, +}); +for (let i = 1; i <= 3; i++) { + verifyCompletionsInJsDocType(i.toString() + "TypeMember", { + verifyType: verifySymbolPresentWithWarning, + verifyValue: verifySymbolPresentWithWarning, + verifyTypeMember: verifySymbolPresentWithKind, + }); +} +goTo.marker("propertyName"); +verify.completionListIsEmpty(); diff --git a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts new file mode 100644 index 00000000000..b327fdf427b --- /dev/null +++ b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts @@ -0,0 +1,65 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsFileJsdocTypedefTagTypeExpressionCompletion2_typedef.js + +//// class Foo { +//// constructor(value: number) { this.property1 = "hello"; } +//// static method1() {} +//// method3() { return 3; } +//// /** +//// * @param {string} foo A value. +//// * @returns {number} Another value +//// * @mytag +//// */ +//// method4(foo) { return 3; } +//// } +//// /** +//// * @type { /*type*/Foo } +//// */ +////var x; +/////*globalValue*/ +////x./*valueMember*/ + +interface VeriferCompletionsInJsDoc { + verifyValueOrType(symbol: string, kind: string): void; + verifyValue(symbol: string, kind: string): void; + verifyValueMember(symbol: string, kind: string): void; +} + +function verifyCompletionsInJsDocType(marker: string, { verifyValueOrType, verifyValue, verifyValueMember }: VeriferCompletionsInJsDoc) { + goTo.marker(marker); + + verifyValueOrType("Foo", "class"); + + verifyValue("x", "var"); + + verifyValueMember("property1", "property"); + verifyValueMember("method3", "method"); + verifyValueMember("method4", "method"); + verifyValueMember("foo", "warning"); +} + +function verifySymbolPresentWithKind(symbol: string, kind: string) { + return verify.completionListContains(symbol, /*text*/ undefined, /*documentation*/ undefined, kind); +} + +function verifySymbolPresentWithWarning(symbol: string) { + return verifySymbolPresentWithKind(symbol, "warning"); +} + +verifyCompletionsInJsDocType("type", { + verifyValueOrType: verifySymbolPresentWithKind, + verifyValue: verifySymbolPresentWithWarning, + verifyValueMember: verifySymbolPresentWithWarning, +}); +verifyCompletionsInJsDocType("globalValue", { + verifyValueOrType: verifySymbolPresentWithKind, + verifyValue: verifySymbolPresentWithKind, + verifyValueMember: verifySymbolPresentWithWarning, +}); +verifyCompletionsInJsDocType("valueMember", { + verifyValueOrType: verifySymbolPresentWithWarning, + verifyValue: verifySymbolPresentWithWarning, + verifyValueMember: verifySymbolPresentWithKind, +}); diff --git a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion3.ts b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion3.ts new file mode 100644 index 00000000000..66c3856d0b7 --- /dev/null +++ b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion3.ts @@ -0,0 +1,127 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: jsFileJsdocTypedefTagTypeExpressionCompletion3_typedef.js + +//// /** +//// * @typedef {{ age: number }} Foo.Namespace.SomeType +//// */ +//// class Foo { +//// constructor(value) { this.property1 = "hello"; } +//// static method1() {} +//// method3() { return 3; } +//// /** +//// * @param {string} foo A value. +//// * @returns {number} Another value +//// * @mytag +//// */ +//// method4(foo) { return 3; } +//// } +//// /** +//// * @type { /*type1*/Foo./*typeFooMember*/Namespace./*NamespaceMember*/SomeType } +//// */ +////var x; +/////*globalValue*/ +////x./*valueMemberOfSomeType*/ +//// /** +//// * @type { /*type2*/Foo } +//// */ +////var x1; +////x1./*valueMemberOfFooInstance*/; +////Foo./*valueMemberOfFoo*/; + +function verifySymbolPresentWithKind(symbol: string, kind: string) { + return verify.completionListContains(symbol, /*text*/ undefined, /*documentation*/ undefined, kind); +} + +function verifySymbolPresentWithWarning(symbol: string) { + return verifySymbolPresentWithKind(symbol, "warning"); +} + +for (const marker of ["type1", "type2"]) { + goTo.marker(marker); + verifySymbolPresentWithKind("Foo", "class"); + + verifySymbolPresentWithWarning("Namespace"); + verifySymbolPresentWithWarning("SomeType"); + + verifySymbolPresentWithWarning("x"); + verifySymbolPresentWithWarning("x1"); + verifySymbolPresentWithWarning("method1"); + verifySymbolPresentWithWarning("property1"); + verifySymbolPresentWithWarning("method3"); + verifySymbolPresentWithWarning("method4"); + verifySymbolPresentWithWarning("foo"); +} + +goTo.marker("typeFooMember"); +verifySymbolPresentWithWarning("Foo"); +verifySymbolPresentWithKind("Namespace", "module"); +verifySymbolPresentWithWarning("SomeType"); +verifySymbolPresentWithWarning("x"); +verifySymbolPresentWithWarning("x1"); +verifySymbolPresentWithWarning("method1"); +verifySymbolPresentWithWarning("property1"); +verifySymbolPresentWithWarning("method3"); +verifySymbolPresentWithWarning("method4"); +verifySymbolPresentWithWarning("foo"); + +goTo.marker("NamespaceMember"); +verifySymbolPresentWithWarning("Foo"); +verifySymbolPresentWithWarning("Namespace"); +verifySymbolPresentWithKind("SomeType", "type"); +verifySymbolPresentWithWarning("x"); +verifySymbolPresentWithWarning("x1"); +verifySymbolPresentWithWarning("method1"); +verifySymbolPresentWithWarning("property1"); +verifySymbolPresentWithWarning("method3"); +verifySymbolPresentWithWarning("method4"); +verifySymbolPresentWithWarning("foo"); + +goTo.marker("globalValue"); +verifySymbolPresentWithKind("Foo", "class"); +verifySymbolPresentWithWarning("Namespace"); +verifySymbolPresentWithWarning("SomeType"); +verifySymbolPresentWithKind("x", "var"); +verifySymbolPresentWithKind("x1", "var"); +verifySymbolPresentWithWarning("method1"); +verifySymbolPresentWithWarning("property1"); +verifySymbolPresentWithWarning("method3"); +verifySymbolPresentWithWarning("method4"); +verifySymbolPresentWithWarning("foo"); + +goTo.marker("valueMemberOfSomeType"); +verifySymbolPresentWithWarning("Foo"); +verifySymbolPresentWithWarning("Namespace"); +verifySymbolPresentWithWarning("SomeType"); +verifySymbolPresentWithWarning("x"); +verifySymbolPresentWithWarning("x1"); +verifySymbolPresentWithWarning("method1"); +verifySymbolPresentWithWarning("property1"); +verifySymbolPresentWithWarning("method3"); +verifySymbolPresentWithWarning("method4"); +verifySymbolPresentWithWarning("foo"); + +goTo.marker("valueMemberOfFooInstance"); +verifySymbolPresentWithWarning("Foo"); +verifySymbolPresentWithWarning("Namespace"); +verifySymbolPresentWithWarning("SomeType"); +verifySymbolPresentWithWarning("x"); +verifySymbolPresentWithWarning("x1"); +verifySymbolPresentWithWarning("method1"); +verifySymbolPresentWithKind("property1", "property"); +verifySymbolPresentWithKind("method3", "method"); +verifySymbolPresentWithKind("method4", "method"); +verifySymbolPresentWithKind("foo", "warning"); + +goTo.marker("valueMemberOfFoo"); +verifySymbolPresentWithWarning("Foo"); +verifySymbolPresentWithWarning("Namespace"); +verifySymbolPresentWithWarning("SomeType"); +verifySymbolPresentWithWarning("x"); +verifySymbolPresentWithWarning("x1"); +verifySymbolPresentWithKind("method1", "method"); +verifySymbolPresentWithWarning("property1"); +verifySymbolPresentWithWarning("method3"); +verifySymbolPresentWithWarning("method4"); +verifySymbolPresentWithWarning("foo"); \ No newline at end of file diff --git a/tests/cases/fourslash/jsdocTypedefTagTypeExpressionCompletion.ts b/tests/cases/fourslash/jsdocTypedefTagTypeExpressionCompletion.ts new file mode 100644 index 00000000000..379cc60e058 --- /dev/null +++ b/tests/cases/fourslash/jsdocTypedefTagTypeExpressionCompletion.ts @@ -0,0 +1,140 @@ +/// + +////interface I { +//// age: number; +////} +//// class Foo { +//// property1: string; +//// constructor(value: number) { this.property1 = "hello"; } +//// static method1() {} +//// method3(): number { return 3; } +//// /** +//// * @param {string} foo A value. +//// * @returns {number} Another value +//// * @mytag +//// */ +//// method4(foo: string) { return 3; } +//// } +//// namespace Foo.Namespace { export interface SomeType { age2: number } } +//// /** +//// * @type { /*type1*/Foo./*typeFooMember*/Namespace./*NamespaceMember*/SomeType } +//// */ +////var x; +/////*globalValue*/ +////x./*valueMemberOfSomeType*/ +////var x1: Foo; +////x1./*valueMemberOfFooInstance*/; +////Foo./*valueMemberOfFoo*/; +//// /** +//// * @type { {/*propertyName*/ageX: number} } +//// */ +////var y; + +function verifySymbolPresentWithKind(symbol: string, kind: string) { + return verify.completionListContains(symbol, /*text*/ undefined, /*documentation*/ undefined, kind); +} + +function verifySymbolNotPresent(symbol: string) { + return verify.not.completionListContains(symbol); +} + +goTo.marker("type1"); +verifySymbolPresentWithKind("Foo", "class"); +verifySymbolPresentWithKind("I", "interface"); +verifySymbolNotPresent("Namespace"); +verifySymbolNotPresent("SomeType"); +verifySymbolNotPresent("x"); +verifySymbolNotPresent("x1"); +verifySymbolNotPresent("y"); +verifySymbolNotPresent("method1"); +verifySymbolNotPresent("property1"); +verifySymbolNotPresent("method3"); +verifySymbolNotPresent("method4"); +verifySymbolNotPresent("foo"); + +goTo.marker("typeFooMember"); +verifySymbolNotPresent("Foo"); +verifySymbolNotPresent("I"); +verifySymbolPresentWithKind("Namespace", "module"); +verifySymbolNotPresent("SomeType"); +verifySymbolNotPresent("x"); +verifySymbolNotPresent("x1"); +verifySymbolNotPresent("y"); +verifySymbolNotPresent("method1"); +verifySymbolNotPresent("property1"); +verifySymbolNotPresent("method3"); +verifySymbolNotPresent("method4"); +verifySymbolNotPresent("foo"); + +goTo.marker("NamespaceMember"); +verifySymbolNotPresent("Foo"); +verifySymbolNotPresent("I"); +verifySymbolNotPresent("Namespace"); +verifySymbolPresentWithKind("SomeType", "interface"); +verifySymbolNotPresent("x"); +verifySymbolNotPresent("x1"); +verifySymbolNotPresent("y"); +verifySymbolNotPresent("method1"); +verifySymbolNotPresent("property1"); +verifySymbolNotPresent("method3"); +verifySymbolNotPresent("method4"); +verifySymbolNotPresent("foo"); + +goTo.marker("globalValue"); +verifySymbolPresentWithKind("Foo", "class"); +verifySymbolNotPresent("I"); +verifySymbolNotPresent("Namespace"); +verifySymbolNotPresent("SomeType"); +verifySymbolPresentWithKind("x", "var"); +verifySymbolPresentWithKind("x1", "var"); +verifySymbolPresentWithKind("y", "var"); +verifySymbolNotPresent("method1"); +verifySymbolNotPresent("property1"); +verifySymbolNotPresent("method3"); +verifySymbolNotPresent("method4"); +verifySymbolNotPresent("foo"); + +goTo.marker("valueMemberOfSomeType"); +verifySymbolNotPresent("Foo"); +verifySymbolNotPresent("I"); +verifySymbolNotPresent("Namespace"); +verifySymbolNotPresent("SomeType"); +verifySymbolNotPresent("x"); +verifySymbolNotPresent("x1"); +verifySymbolNotPresent("y"); +verifySymbolNotPresent("method1"); +verifySymbolNotPresent("property1"); +verifySymbolNotPresent("method3"); +verifySymbolNotPresent("method4"); +verifySymbolNotPresent("foo"); + +goTo.marker("valueMemberOfFooInstance"); +verifySymbolNotPresent("Foo"); +verifySymbolNotPresent("I"); +verifySymbolNotPresent("Namespace"); +verifySymbolNotPresent("SomeType"); +verifySymbolNotPresent("x"); +verifySymbolNotPresent("x1"); +verifySymbolNotPresent("y"); +verifySymbolNotPresent("method1"); +verifySymbolPresentWithKind("property1", "property"); +verifySymbolPresentWithKind("method3", "method"); +verifySymbolPresentWithKind("method4", "method"); +verifySymbolNotPresent("foo"); + +goTo.marker("valueMemberOfFoo"); +verifySymbolNotPresent("Foo"); +verifySymbolNotPresent("I"); +verifySymbolNotPresent("Namespace"); +verifySymbolNotPresent("SomeType"); +verifySymbolNotPresent("x"); +verifySymbolNotPresent("x1"); +verifySymbolNotPresent("y"); +verifySymbolPresentWithKind("method1", "method"); +verifySymbolNotPresent("property1"); +verifySymbolNotPresent("method3"); +verifySymbolNotPresent("method4"); +verifySymbolNotPresent("foo"); + +goTo.marker("propertyName"); +verify.completionListIsEmpty(); \ No newline at end of file From 556e268bd0b0f065038143c6a724a11677705e7e Mon Sep 17 00:00:00 2001 From: Charles Pierce Date: Thu, 1 Jun 2017 20:37:52 -0700 Subject: [PATCH 005/138] #15943 #15981 Update special cases for await / yield parsing --- src/compiler/parser.ts | 8 ++-- .../reference/awaitLiteralValues.errors.txt | 45 +++++++++++++++++++ .../baselines/reference/awaitLiteralValues.js | 45 +++++++++++++++++++ .../reference/yieldStringLiteral.errors.txt | 10 +++++ .../baselines/reference/yieldStringLiteral.js | 10 +++++ tests/cases/compiler/awaitLiteralValues.ts | 23 ++++++++++ tests/cases/compiler/yieldStringLiteral.ts | 3 ++ 7 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/awaitLiteralValues.errors.txt create mode 100644 tests/baselines/reference/awaitLiteralValues.js create mode 100644 tests/baselines/reference/yieldStringLiteral.errors.txt create mode 100644 tests/baselines/reference/yieldStringLiteral.js create mode 100644 tests/cases/compiler/awaitLiteralValues.ts create mode 100644 tests/cases/compiler/yieldStringLiteral.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 849f97bbbaf..966a6d432c1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2960,7 +2960,7 @@ namespace ts { // for now we just check if the next token is an identifier. More heuristics // can be added here later as necessary. We just need to make sure that we // don't accidentally consume something legal. - return lookAhead(nextTokenIsIdentifierOrKeywordOrNumberOnSameLine); + return lookAhead(nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine); } return false; @@ -3478,7 +3478,7 @@ namespace ts { } // here we are using similar heuristics as 'isYieldExpression' - return lookAhead(nextTokenIsIdentifierOnSameLine); + return lookAhead(nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine); } return false; @@ -4677,9 +4677,9 @@ namespace ts { return token() === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak(); } - function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() { + function nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine() { nextToken(); - return (tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak(); + return (tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.NumericLiteral || token() === SyntaxKind.StringLiteral) && !scanner.hasPrecedingLineBreak(); } function isDeclaration(): boolean { diff --git a/tests/baselines/reference/awaitLiteralValues.errors.txt b/tests/baselines/reference/awaitLiteralValues.errors.txt new file mode 100644 index 00000000000..cf3e155c280 --- /dev/null +++ b/tests/baselines/reference/awaitLiteralValues.errors.txt @@ -0,0 +1,45 @@ +tests/cases/compiler/awaitLiteralValues.ts(2,5): error TS1308: 'await' expression is only allowed within an async function. +tests/cases/compiler/awaitLiteralValues.ts(6,5): error TS1308: 'await' expression is only allowed within an async function. +tests/cases/compiler/awaitLiteralValues.ts(10,5): error TS1308: 'await' expression is only allowed within an async function. +tests/cases/compiler/awaitLiteralValues.ts(14,5): error TS1308: 'await' expression is only allowed within an async function. +tests/cases/compiler/awaitLiteralValues.ts(18,5): error TS1308: 'await' expression is only allowed within an async function. +tests/cases/compiler/awaitLiteralValues.ts(22,5): error TS1308: 'await' expression is only allowed within an async function. + + +==== tests/cases/compiler/awaitLiteralValues.ts (6 errors) ==== + function awaitString() { + await 'literal'; + ~~~~~ +!!! error TS1308: 'await' expression is only allowed within an async function. + } + + function awaitNumber() { + await 1; + ~~~~~ +!!! error TS1308: 'await' expression is only allowed within an async function. + } + + function awaitTrue() { + await true; + ~~~~~ +!!! error TS1308: 'await' expression is only allowed within an async function. + } + + function awaitFalse() { + await false; + ~~~~~ +!!! error TS1308: 'await' expression is only allowed within an async function. + } + + function awaitNull() { + await null; + ~~~~~ +!!! error TS1308: 'await' expression is only allowed within an async function. + } + + function awaitUndefined() { + await undefined; + ~~~~~ +!!! error TS1308: 'await' expression is only allowed within an async function. + } + \ No newline at end of file diff --git a/tests/baselines/reference/awaitLiteralValues.js b/tests/baselines/reference/awaitLiteralValues.js new file mode 100644 index 00000000000..cc5a06a0c19 --- /dev/null +++ b/tests/baselines/reference/awaitLiteralValues.js @@ -0,0 +1,45 @@ +//// [awaitLiteralValues.ts] +function awaitString() { + await 'literal'; +} + +function awaitNumber() { + await 1; +} + +function awaitTrue() { + await true; +} + +function awaitFalse() { + await false; +} + +function awaitNull() { + await null; +} + +function awaitUndefined() { + await undefined; +} + + +//// [awaitLiteralValues.js] +function awaitString() { + yield 'literal'; +} +function awaitNumber() { + yield 1; +} +function awaitTrue() { + yield true; +} +function awaitFalse() { + yield false; +} +function awaitNull() { + yield null; +} +function awaitUndefined() { + yield undefined; +} diff --git a/tests/baselines/reference/yieldStringLiteral.errors.txt b/tests/baselines/reference/yieldStringLiteral.errors.txt new file mode 100644 index 00000000000..6d3cf565757 --- /dev/null +++ b/tests/baselines/reference/yieldStringLiteral.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/yieldStringLiteral.ts(2,5): error TS1163: A 'yield' expression is only allowed in a generator body. + + +==== tests/cases/compiler/yieldStringLiteral.ts (1 errors) ==== + function yieldString() { + yield 'literal'; + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + } + \ No newline at end of file diff --git a/tests/baselines/reference/yieldStringLiteral.js b/tests/baselines/reference/yieldStringLiteral.js new file mode 100644 index 00000000000..99f5c49709b --- /dev/null +++ b/tests/baselines/reference/yieldStringLiteral.js @@ -0,0 +1,10 @@ +//// [yieldStringLiteral.ts] +function yieldString() { + yield 'literal'; +} + + +//// [yieldStringLiteral.js] +function yieldString() { + yield 'literal'; +} diff --git a/tests/cases/compiler/awaitLiteralValues.ts b/tests/cases/compiler/awaitLiteralValues.ts new file mode 100644 index 00000000000..ab7de0d156a --- /dev/null +++ b/tests/cases/compiler/awaitLiteralValues.ts @@ -0,0 +1,23 @@ +function awaitString() { + await 'literal'; +} + +function awaitNumber() { + await 1; +} + +function awaitTrue() { + await true; +} + +function awaitFalse() { + await false; +} + +function awaitNull() { + await null; +} + +function awaitUndefined() { + await undefined; +} diff --git a/tests/cases/compiler/yieldStringLiteral.ts b/tests/cases/compiler/yieldStringLiteral.ts new file mode 100644 index 00000000000..3faa03345a8 --- /dev/null +++ b/tests/cases/compiler/yieldStringLiteral.ts @@ -0,0 +1,3 @@ +function yieldString() { + yield 'literal'; +} From dbf036298db36fa48940a8e6549a8607ea1ce562 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 3 Jun 2017 16:44:58 -0700 Subject: [PATCH 006/138] Include SymbolFlags.Function in couldContainTypeVariables check --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b3084f9cbd..b2f34987a8d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10239,7 +10239,7 @@ namespace ts { const objectFlags = getObjectFlags(type); return !!(type.flags & TypeFlags.TypeVariable || objectFlags & ObjectFlags.Reference && forEach((type).typeArguments, couldContainTypeVariables) || - objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class) || + objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class) || objectFlags & ObjectFlags.Mapped || type.flags & TypeFlags.UnionOrIntersection && couldUnionOrIntersectionContainTypeVariables(type)); } From 9e613b9fd54495bb5d980498c15fc83e2430b5e3 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 3 Jun 2017 16:52:38 -0700 Subject: [PATCH 007/138] Preserve type parameters in generic contextual pure function types --- src/compiler/checker.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b2f34987a8d..5ad2ffeac6e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14959,11 +14959,21 @@ namespace ts { // We clone the contextual mapper to avoid disturbing a resolution in progress for an // outer call expression. Effectively we just want a snapshot of whatever has been // inferred for any outer call expression so far. - const mapper = cloneTypeMapper(getContextualMapper(node)); - const instantiatedType = instantiateType(contextualType, mapper); - const returnType = getReturnTypeOfSignature(signature); - // Inferences made from return types have lower priority than all other inferences. - inferTypes(context.inferences, instantiatedType, returnType, InferencePriority.ReturnType); + 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: + // 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'. + const contextualSignature = getSingleCallSignature(instantiatedType); + const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ? + getOrCreateTypeFromSignature(getSignatureInstantiation(contextualSignature, contextualSignature.typeParameters)) : + instantiatedType; + const inferenceTargetType = getReturnTypeOfSignature(signature); + // Inferences made from return types have lower priority than all other inferences. + inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, InferencePriority.ReturnType); } } From b62f5b0dae77b9392cc806e3a41c191d6ec79e65 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 5 Jun 2017 17:09:40 -0700 Subject: [PATCH 008/138] Typos in test cases --- .../jsFileJsdocTypedefTagTypeExpressionCompletion.ts | 4 ++-- .../jsFileJsdocTypedefTagTypeExpressionCompletion2.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts index 62046458e4c..d6c3ca4f914 100644 --- a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts +++ b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts @@ -16,13 +16,13 @@ //// var x1; //// /*globalValue*/ -interface VeriferCompletionsInJsDoc { +interface VerifyCompletionsInJsDoc { verifyType(symbol: string, kind: string): void; verifyValue(symbol: string, kind: string): void; verifyTypeMember(symbol: string, kind: string): void; } -function verifyCompletionsInJsDocType(marker: string, { verifyType, verifyValue, verifyTypeMember }: VeriferCompletionsInJsDoc) { +function verifyCompletionsInJsDocType(marker: string, { verifyType, verifyValue, verifyTypeMember }: VerifyCompletionsInJsDoc) { goTo.marker(marker); verifyType("T", "module"); diff --git a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts index b327fdf427b..038c5db5528 100644 --- a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts +++ b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts @@ -21,13 +21,13 @@ /////*globalValue*/ ////x./*valueMember*/ -interface VeriferCompletionsInJsDoc { +interface VerifyCompletionsInJsDoc { verifyValueOrType(symbol: string, kind: string): void; verifyValue(symbol: string, kind: string): void; verifyValueMember(symbol: string, kind: string): void; } -function verifyCompletionsInJsDocType(marker: string, { verifyValueOrType, verifyValue, verifyValueMember }: VeriferCompletionsInJsDoc) { +function verifyCompletionsInJsDocType(marker: string, { verifyValueOrType, verifyValue, verifyValueMember }: VerifyCompletionsInJsDoc) { goTo.marker(marker); verifyValueOrType("Foo", "class"); From b5f81f9eded21079d2a7575085080875f40ec1bf Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 5 Jun 2017 18:39:32 -0700 Subject: [PATCH 009/138] Fix emit when type import merges with local value --- Jakefile.js | 2 +- src/compiler/checker.ts | 17 ++++++++++++--- .../symbolMergeValueAndImportedType.js | 17 +++++++++++++++ .../symbolMergeValueAndImportedType.symbols | 17 +++++++++++++++ .../symbolMergeValueAndImportedType.types | 21 +++++++++++++++++++ .../symbolMergeValueAndImportedType.ts | 9 ++++++++ 6 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/symbolMergeValueAndImportedType.js create mode 100644 tests/baselines/reference/symbolMergeValueAndImportedType.symbols create mode 100644 tests/baselines/reference/symbolMergeValueAndImportedType.types create mode 100644 tests/cases/compiler/symbolMergeValueAndImportedType.ts diff --git a/Jakefile.js b/Jakefile.js index 439fced0720..ce173525a84 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -925,7 +925,7 @@ function runConsoleTests(defaultReporter, runInParallel) { } } -var testTimeout = 20000; +var testTimeout = 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); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1ab88880d9e..62bfbe0df6c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1473,8 +1473,15 @@ namespace ts { } } + /** + * Indicates that a symbol is an alias that does not merge with a local declaration. + */ + function isNonLocalAlias(symbol: Symbol, excludes = SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace) { + return symbol && (symbol.flags & (SymbolFlags.Alias | excludes)) === SymbolFlags.Alias; + } + function resolveSymbol(symbol: Symbol, dontResolveAlias?: boolean): Symbol { - const shouldResolve = !dontResolveAlias && symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace)); + const shouldResolve = !dontResolveAlias && isNonLocalAlias(symbol); return shouldResolve ? resolveAlias(symbol) : symbol; } @@ -12015,7 +12022,9 @@ namespace ts { return getTypeOfSymbol(symbol); } - if (symbol.flags & SymbolFlags.Alias && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { + // We should only mark aliases as referenced if there isn't a local value declaration + // for the symbol. + if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { markAliasSymbolAsReferenced(symbol); } @@ -22864,7 +22873,9 @@ namespace ts { node = getParseTreeNode(node, isIdentifier); if (node) { const symbol = getReferencedValueSymbol(node); - if (symbol && symbol.flags & SymbolFlags.Alias) { + // We should only get the declaration of an alias if there isn't a local value + // declaration for the symbol + if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value)) { return getDeclarationOfAliasSymbol(symbol); } } diff --git a/tests/baselines/reference/symbolMergeValueAndImportedType.js b/tests/baselines/reference/symbolMergeValueAndImportedType.js new file mode 100644 index 00000000000..70da47268d5 --- /dev/null +++ b/tests/baselines/reference/symbolMergeValueAndImportedType.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/symbolMergeValueAndImportedType.ts] //// + +//// [main.ts] +import { X } from "./other"; +const X = 42; +console.log('X is ' + X); +//// [other.ts] +export type X = {}; + +//// [other.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//// [main.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const X = 42; +console.log('X is ' + X); diff --git a/tests/baselines/reference/symbolMergeValueAndImportedType.symbols b/tests/baselines/reference/symbolMergeValueAndImportedType.symbols new file mode 100644 index 00000000000..7e1422faa46 --- /dev/null +++ b/tests/baselines/reference/symbolMergeValueAndImportedType.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/main.ts === +import { X } from "./other"; +>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5)) + +const X = 42; +>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5)) + +console.log('X is ' + X); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5)) + +=== tests/cases/compiler/other.ts === +export type X = {}; +>X : Symbol(X, Decl(other.ts, 0, 0)) + diff --git a/tests/baselines/reference/symbolMergeValueAndImportedType.types b/tests/baselines/reference/symbolMergeValueAndImportedType.types new file mode 100644 index 00000000000..a7dc72ab0b6 --- /dev/null +++ b/tests/baselines/reference/symbolMergeValueAndImportedType.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/main.ts === +import { X } from "./other"; +>X : 42 + +const X = 42; +>X : 42 +>42 : 42 + +console.log('X is ' + X); +>console.log('X is ' + X) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>'X is ' + X : string +>'X is ' : "X is " +>X : 42 + +=== tests/cases/compiler/other.ts === +export type X = {}; +>X : X + diff --git a/tests/cases/compiler/symbolMergeValueAndImportedType.ts b/tests/cases/compiler/symbolMergeValueAndImportedType.ts new file mode 100644 index 00000000000..4779ff22e9d --- /dev/null +++ b/tests/cases/compiler/symbolMergeValueAndImportedType.ts @@ -0,0 +1,9 @@ +// @target: es2015 +// @module: commonjs +// @lib: es2015,dom +// @filename: main.ts +import { X } from "./other"; +const X = 42; +console.log('X is ' + X); +// @filename: other.ts +export type X = {}; \ No newline at end of file From 368e5af162c341dad6bb5db8d1c4ed6c843024e1 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 6 Jun 2017 09:49:50 -0700 Subject: [PATCH 010/138] Stricter type relationship checking of generic signatures --- src/compiler/checker.ts | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b3084f9cbd..b5b5af9d8d8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8408,10 +8408,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; @@ -9446,23 +9445,32 @@ 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 pure 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. + result = signatureRelatedTo(sourceSignatures[0], targetSignatures[0], /*erase*/ relation === comparableRelation, 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; @@ -9485,8 +9493,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 { @@ -14915,12 +14924,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)); } From 65a48ca15dafc303e03b4eaf8663f68ea6fabb3b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 6 Jun 2017 11:27:31 -0700 Subject: [PATCH 011/138] Encorporting feedback --- Gulpfile.ts | 2 +- src/services/completions.ts | 10 +++------- tests/cases/fourslash/completionListWithMeanings.ts | 2 ++ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Gulpfile.ts b/Gulpfile.ts index d856254296e..c2724b5fb10 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -745,7 +745,7 @@ declare module "convert-source-map" { export function fromSource(source: string, largeSource?: boolean): SourceMapConverter; } -gulp.task("browserify", "Runs browserify on run.js to produce a file suitable for running tests in the browser", [servicesFile], (done) => { +gulp.task("browserify", "Runs browserify on run.js to produce a file suitable for running tests in the browser", [servicesFile, run], (done) => { const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "../../built/local/bundle.js" }, /*useBuiltCompiler*/ true)); return testProject.src() .pipe(newer("built/local/bundle.js")) diff --git a/src/services/completions.ts b/src/services/completions.ts index 7c0662c7531..8b11eb74e61 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -749,13 +749,9 @@ namespace ts.Completions { } function isContextTokenValueLocation(contextToken: Node) { - if (contextToken) { - const parentKind = contextToken.parent.kind; - switch (contextToken.kind) { - case SyntaxKind.TypeOfKeyword: - return parentKind === SyntaxKind.TypeQuery; - } - } + return contextToken && + contextToken.kind === SyntaxKind.TypeOfKeyword && + contextToken.parent.kind === SyntaxKind.TypeQuery; } function isContextTokenTypeLocation(contextToken: Node) { diff --git a/tests/cases/fourslash/completionListWithMeanings.ts b/tests/cases/fourslash/completionListWithMeanings.ts index 995bec8bd66..61dc95adca8 100644 --- a/tests/cases/fourslash/completionListWithMeanings.ts +++ b/tests/cases/fourslash/completionListWithMeanings.ts @@ -11,6 +11,7 @@ ////var tt = /*valueExpr*/xx; ////var yy: /*typeExpr*/point = { x: 4, y: 3 + /*valueExprInObjectLiteral*/tt }; ////var kk: m3.point3/*membertypeExpr*/ = m3.zz2/*membervalueExpr*/; +////var zz = { x: 4, y: 3 }; const markers = test.markerNames(); @@ -37,6 +38,7 @@ const values: CompletionInfo[] = [ ["xx", "var xx: number"], ["tt", "var tt: number"], ["yy", "var yy: point"], + ["zz", "var zz: point"], ["m2", "namespace m2"], // With no type side, allowed only in value ]; From 0f6f8577020eaa13f245cb1baee66a81c802fa0e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 6 Jun 2017 11:38:50 -0700 Subject: [PATCH 012/138] Allow contextual signature to be generic --- src/compiler/checker.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5ad2ffeac6e..c32cb8d9acc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13042,13 +13042,13 @@ namespace ts { return node ? node.contextualMapper : identityMapper; } - // If the given type is an object or union type, if that type has a single signature, and if - // that signature is non-generic, return the signature. Otherwise return undefined. - function getNonGenericSignature(type: Type, node: FunctionExpression | ArrowFunction | MethodDeclaration): Signature { + // If the given type is an object or union type with a single signature, and if that signature has at + // least as many parameters as the given function, return the signature. Otherwise return undefined. + function getContextualCallSignature(type: Type, node: FunctionExpression | ArrowFunction | MethodDeclaration): Signature { const signatures = getSignaturesOfStructuredType(type, SignatureKind.Call); if (signatures.length === 1) { const signature = signatures[0]; - if (!signature.typeParameters && !isAritySmaller(signature, node)) { + if (!isAritySmaller(signature, node)) { return signature; } } @@ -13099,12 +13099,12 @@ namespace ts { return undefined; } if (!(type.flags & TypeFlags.Union)) { - return getNonGenericSignature(type, node); + return getContextualCallSignature(type, node); } let signatureList: Signature[]; const types = (type).types; for (const current of types) { - const signature = getNonGenericSignature(current, node); + const signature = getContextualCallSignature(current, node); if (signature) { if (!signatureList) { // This signature will contribute to contextual union signature From f17a612de81433002c06e521c876a35b18f23afe Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 6 Jun 2017 13:13:46 -0700 Subject: [PATCH 013/138] rename codeFix --- src/harness/tsconfig.json | 2 +- .../{unusedIdentifierFixes.ts => fixUnusedIdentifier.ts} | 0 src/services/codefixes/fixes.ts | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename src/services/codefixes/{unusedIdentifierFixes.ts => fixUnusedIdentifier.ts} (100%) diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index 6553f3667a7..7366df94ef6 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -80,7 +80,7 @@ "../services/codefixes/fixConstructorForDerivedNeedSuperCall.ts", "../services/codefixes/helpers.ts", "../services/codefixes/importFixes.ts", - "../services/codefixes/unusedIdentifierFixes.ts", + "../services/codefixes/fixUnusedIdentifier.ts", "../services/codefixes/disableJsDiagnostics.ts", "harness.ts", diff --git a/src/services/codefixes/unusedIdentifierFixes.ts b/src/services/codefixes/fixUnusedIdentifier.ts similarity index 100% rename from src/services/codefixes/unusedIdentifierFixes.ts rename to src/services/codefixes/fixUnusedIdentifier.ts diff --git a/src/services/codefixes/fixes.ts b/src/services/codefixes/fixes.ts index c2e2509a28e..c38820231b0 100644 --- a/src/services/codefixes/fixes.ts +++ b/src/services/codefixes/fixes.ts @@ -6,7 +6,7 @@ /// /// /// -/// +/// /// /// /// From 634c75c4262b2adeb25e7c2068f951351981e415 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 6 Jun 2017 13:25:29 -0700 Subject: [PATCH 014/138] Fix fourslash tests --- ...ontextualTypingOfGenericCallSignatures2.ts | 2 +- ...extuallyTypedFunctionExpressionGeneric1.ts | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts b/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts index 0f610a2a539..7bc95085e22 100644 --- a/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts +++ b/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts @@ -7,5 +7,5 @@ ////// x should not be contextually typed so this should be an error ////f6(/**/x => x()) -verify.quickInfoAt("", "(parameter) x: any"); +verify.quickInfoAt("", "(parameter) x: T extends T"); verify.numberOfErrorsInCurrentFile(1); diff --git a/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts b/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts index a33e2cc5e7a..7337a429d9c 100644 --- a/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts +++ b/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts @@ -1,17 +1,17 @@ /// -////interface Comparable { -//// compareTo(other: T): T; -////} -////interface Comparer { -//// >(x: T, y: T): T; -////} +interface Comparable { + compareTo(other: T): T; +} +interface Comparer { + >(x: T, y: T): T; +} -////var max2: Comparer = (x/*1*/x, y/*2*/y) => { return x/*3*/x.compareTo(y/*4*/y) }; +//var max2: Comparer = (x/*1*/x, y/*2*/y) => { return x/*3*/x.compareTo(y/*4*/y) }; verify.quickInfos({ - 1: "(parameter) xx: any", - 2: "(parameter) yy: any", - 3: "(parameter) xx: any", - 4: "(parameter) yy: any" + 1: "(parameter) xx: T extends Comparable", + 2: "(parameter) yy: T extends Comparable", + 3: "(parameter) xx: T extends Comparable", + 4: "(parameter) yy: T extends Comparable" }); From 8a7693908d4f894d8804280e667fe70f5aff2e4a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 6 Jun 2017 13:26:39 -0700 Subject: [PATCH 015/138] Accept new baselines --- ...contextualTypingWithGenericSignature.types | 10 ++--- .../genericFunctionHasFreshTypeArgs.types | 14 +++---- .../reference/genericTypeAssertions3.types | 6 +-- ...implicitAnyGenericTypeInference.errors.txt | 16 -------- .../implicitAnyGenericTypeInference.symbols | 32 ++++++++++++++++ .../implicitAnyGenericTypeInference.types | 38 +++++++++++++++++++ 6 files changed, 85 insertions(+), 31 deletions(-) delete mode 100644 tests/baselines/reference/implicitAnyGenericTypeInference.errors.txt create mode 100644 tests/baselines/reference/implicitAnyGenericTypeInference.symbols create mode 100644 tests/baselines/reference/implicitAnyGenericTypeInference.types diff --git a/tests/baselines/reference/contextualTypingWithGenericSignature.types b/tests/baselines/reference/contextualTypingWithGenericSignature.types index 68c5f3c422d..e662f2c4192 100644 --- a/tests/baselines/reference/contextualTypingWithGenericSignature.types +++ b/tests/baselines/reference/contextualTypingWithGenericSignature.types @@ -16,10 +16,10 @@ var f2: { }; f2 = (x, y) => { return x } ->f2 = (x, y) => { return x } : (x: any, y: any) => any +>f2 = (x, y) => { return x } : (x: T, y: U) => T >f2 : (x: T, y: U) => T ->(x, y) => { return x } : (x: any, y: any) => any ->x : any ->y : any ->x : any +>(x, y) => { return x } : (x: T, y: U) => T +>x : T +>y : U +>x : T diff --git a/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types b/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types index 3a3afebb9ac..d6f64bdc933 100644 --- a/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types +++ b/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types @@ -9,13 +9,13 @@ 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: any) => void ->x : any +>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: any) => any ->y : any ->x = y : any ->x : any ->y : any +>y => x = y : (y: T) => T +>y : T +>x = y : T +>x : T +>y : T diff --git a/tests/baselines/reference/genericTypeAssertions3.types b/tests/baselines/reference/genericTypeAssertions3.types index 9f7facc8d47..e46dd4aaa4e 100644 --- a/tests/baselines/reference/genericTypeAssertions3.types +++ b/tests/baselines/reference/genericTypeAssertions3.types @@ -6,9 +6,9 @@ var r = < (x: T) => T > ((x) => { return null; }); // bug was 'could not find >x : T >T : T >T : T ->((x) => { return null; }) : (x: any) => any ->(x) => { return null; } : (x: any) => any ->x : any +>((x) => { return null; }) : (x: T) => any +>(x) => { return null; } : (x: T) => any +>x : T >null : null var s = < (x: T) => T > ((x: any) => { return null; }); // no error diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.errors.txt b/tests/baselines/reference/implicitAnyGenericTypeInference.errors.txt deleted file mode 100644 index 0c64c3e6125..00000000000 --- a/tests/baselines/reference/implicitAnyGenericTypeInference.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/compiler/implicitAnyGenericTypeInference.ts(6,19): error TS7006: Parameter 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyGenericTypeInference.ts(6,22): error TS7006: Parameter 'y' implicitly has an 'any' type. - - -==== tests/cases/compiler/implicitAnyGenericTypeInference.ts (2 errors) ==== - interface Comparer { - compareTo(x: T, y: U): U; - } - - var c: Comparer; - c = { compareTo: (x, y) => { return y; } }; - ~ -!!! error TS7006: Parameter 'x' implicitly has an 'any' type. - ~ -!!! error TS7006: Parameter 'y' implicitly has an 'any' type. - var r = c.compareTo(1, ''); \ No newline at end of file diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.symbols b/tests/baselines/reference/implicitAnyGenericTypeInference.symbols new file mode 100644 index 00000000000..e56b68a7134 --- /dev/null +++ b/tests/baselines/reference/implicitAnyGenericTypeInference.symbols @@ -0,0 +1,32 @@ +=== tests/cases/compiler/implicitAnyGenericTypeInference.ts === +interface Comparer { +>Comparer : Symbol(Comparer, Decl(implicitAnyGenericTypeInference.ts, 0, 0)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 0, 19)) + + compareTo(x: T, y: U): U; +>compareTo : Symbol(Comparer.compareTo, Decl(implicitAnyGenericTypeInference.ts, 0, 23)) +>U : Symbol(U, Decl(implicitAnyGenericTypeInference.ts, 1, 14)) +>x : Symbol(x, Decl(implicitAnyGenericTypeInference.ts, 1, 17)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 0, 19)) +>y : Symbol(y, Decl(implicitAnyGenericTypeInference.ts, 1, 22)) +>U : Symbol(U, Decl(implicitAnyGenericTypeInference.ts, 1, 14)) +>U : Symbol(U, Decl(implicitAnyGenericTypeInference.ts, 1, 14)) +} + +var c: Comparer; +>c : Symbol(c, Decl(implicitAnyGenericTypeInference.ts, 4, 3)) +>Comparer : Symbol(Comparer, Decl(implicitAnyGenericTypeInference.ts, 0, 0)) + +c = { compareTo: (x, y) => { return y; } }; +>c : Symbol(c, Decl(implicitAnyGenericTypeInference.ts, 4, 3)) +>compareTo : Symbol(compareTo, Decl(implicitAnyGenericTypeInference.ts, 5, 5)) +>x : Symbol(x, Decl(implicitAnyGenericTypeInference.ts, 5, 18)) +>y : Symbol(y, Decl(implicitAnyGenericTypeInference.ts, 5, 20)) +>y : Symbol(y, Decl(implicitAnyGenericTypeInference.ts, 5, 20)) + +var r = c.compareTo(1, ''); +>r : Symbol(r, Decl(implicitAnyGenericTypeInference.ts, 6, 3)) +>c.compareTo : Symbol(Comparer.compareTo, Decl(implicitAnyGenericTypeInference.ts, 0, 23)) +>c : Symbol(c, Decl(implicitAnyGenericTypeInference.ts, 4, 3)) +>compareTo : Symbol(Comparer.compareTo, Decl(implicitAnyGenericTypeInference.ts, 0, 23)) + diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.types b/tests/baselines/reference/implicitAnyGenericTypeInference.types new file mode 100644 index 00000000000..4124c729f14 --- /dev/null +++ b/tests/baselines/reference/implicitAnyGenericTypeInference.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/implicitAnyGenericTypeInference.ts === +interface Comparer { +>Comparer : Comparer +>T : T + + compareTo(x: T, y: U): U; +>compareTo : (x: T, y: U) => U +>U : U +>x : T +>T : T +>y : U +>U : U +>U : U +} + +var c: Comparer; +>c : Comparer +>Comparer : Comparer + +c = { compareTo: (x, y) => { return y; } }; +>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 +>x : any +>y : U +>y : U + +var r = c.compareTo(1, ''); +>r : string +>c.compareTo(1, '') : "" +>c.compareTo : (x: any, y: U) => U +>c : Comparer +>compareTo : (x: any, y: U) => U +>1 : 1 +>'' : "" + From 61223f2ab05cb0924be9766c69f17ad2e0841dc5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 6 Jun 2017 13:26:51 -0700 Subject: [PATCH 016/138] Add tests --- .../reference/genericContextualTypes1.js | 107 ++++++ .../reference/genericContextualTypes1.symbols | 318 +++++++++++++++ .../reference/genericContextualTypes1.types | 362 ++++++++++++++++++ .../typeInference/genericContextualTypes1.ts | 52 +++ 4 files changed, 839 insertions(+) create mode 100644 tests/baselines/reference/genericContextualTypes1.js create mode 100644 tests/baselines/reference/genericContextualTypes1.symbols create mode 100644 tests/baselines/reference/genericContextualTypes1.types create mode 100644 tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts diff --git a/tests/baselines/reference/genericContextualTypes1.js b/tests/baselines/reference/genericContextualTypes1.js new file mode 100644 index 00000000000..94724123330 --- /dev/null +++ b/tests/baselines/reference/genericContextualTypes1.js @@ -0,0 +1,107 @@ +//// [genericContextualTypes1.ts] +type Box = { value: T }; + +declare function wrap(f: (a: A) => B): (a: A) => B; + +declare function compose(f: (a: A) => B, g: (b: B) => C): (a: A) => C; + +declare function list(a: T): T[]; + +declare function unlist(a: T[]): T; + +declare function box(x: V): Box; + +declare function unbox(x: Box): W; + +declare function map(a: T[], f: (x: T) => U): U[]; + +declare function identity(x: T): T; + +declare function zip(a: A, b: B): [A, B]; + +declare function flip(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z; + +const f00: (x: A) => A[] = list; +const f01: (x: A) => A[] = x => [x]; +const f02: (x: A) => A[] = wrap(list); +const f03: (x: A) => A[] = wrap(x => [x]); + +const f10: (x: T) => Box = compose(a => list(a), b => box(b)); +const f11: (x: T) => Box = compose(list, box); +const f12: (x: Box) => T = compose(a => unbox(a), b => unlist(b)); +const f13: (x: Box) => T = compose(unbox, unlist); + +const arrayMap = (f: (x: T) => U) => (a: T[]) => a.map(f); +const arrayFilter = (f: (x: T) => boolean) => (a: T[]) => a.filter(f); + +const f20: (a: string[]) => number[] = arrayMap(x => x.length); +const f21: (a: A[]) => A[][] = arrayMap(x => [x]); +const f22: (a: A[]) => A[] = arrayMap(identity); +const f23: (a: A[]) => Box[] = arrayMap(value => ({ value })); + +const f30: (a: string[]) => string[] = arrayFilter(x => x.length > 10); +const f31: >(a: T[]) => T[] = arrayFilter(x => x.value > 10); + +const f40: (b: B, a: A) => [A, B] = flip(zip); + +// Repro from #16293 + +type fn = (a: A) => A; +const fn: fn = a => a; + + +//// [genericContextualTypes1.js] +"use strict"; +var f00 = list; +var f01 = function (x) { return [x]; }; +var f02 = wrap(list); +var f03 = wrap(function (x) { return [x]; }); +var f10 = compose(function (a) { return list(a); }, function (b) { return box(b); }); +var f11 = compose(list, box); +var f12 = compose(function (a) { return unbox(a); }, function (b) { return unlist(b); }); +var f13 = compose(unbox, unlist); +var arrayMap = function (f) { return function (a) { return a.map(f); }; }; +var arrayFilter = function (f) { return function (a) { return a.filter(f); }; }; +var f20 = arrayMap(function (x) { return x.length; }); +var f21 = arrayMap(function (x) { return [x]; }); +var f22 = arrayMap(identity); +var f23 = arrayMap(function (value) { return ({ value: value }); }); +var f30 = arrayFilter(function (x) { return x.length > 10; }); +var f31 = arrayFilter(function (x) { return x.value > 10; }); +var f40 = flip(zip); +var fn = function (a) { return a; }; + + +//// [genericContextualTypes1.d.ts] +declare type Box = { + value: T; +}; +declare function wrap(f: (a: A) => B): (a: A) => B; +declare function compose(f: (a: A) => B, g: (b: B) => C): (a: A) => C; +declare function list(a: T): T[]; +declare function unlist(a: T[]): T; +declare function box(x: V): Box; +declare function unbox(x: Box): W; +declare function map(a: T[], f: (x: T) => U): U[]; +declare function identity(x: T): T; +declare function zip(a: A, b: B): [A, B]; +declare function flip(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z; +declare const f00: (x: A) => A[]; +declare const f01: (x: A) => A[]; +declare const f02: (x: A) => A[]; +declare const f03: (x: A) => A[]; +declare const f10: (x: T) => Box; +declare const f11: (x: T) => Box; +declare const f12: (x: Box) => T; +declare const f13: (x: Box) => T; +declare const arrayMap: (f: (x: T) => U) => (a: T[]) => U[]; +declare const arrayFilter: (f: (x: T) => boolean) => (a: T[]) => T[]; +declare const f20: (a: string[]) => number[]; +declare const f21: (a: A[]) => A[][]; +declare const f22: (a: A[]) => A[]; +declare const f23: (a: A[]) => Box[]; +declare const f30: (a: string[]) => string[]; +declare const f31: >(a: T[]) => T[]; +declare const f40: (b: B, a: A) => [A, B]; +declare type fn = (a: A) => A; +declare const fn: fn; diff --git a/tests/baselines/reference/genericContextualTypes1.symbols b/tests/baselines/reference/genericContextualTypes1.symbols new file mode 100644 index 00000000000..ac11026745d --- /dev/null +++ b/tests/baselines/reference/genericContextualTypes1.symbols @@ -0,0 +1,318 @@ +=== tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts === +type Box = { value: T }; +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 0, 9)) +>value : Symbol(value, Decl(genericContextualTypes1.ts, 0, 15)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 0, 9)) + +declare function wrap(f: (a: A) => B): (a: A) => B; +>wrap : Symbol(wrap, Decl(genericContextualTypes1.ts, 0, 27)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 2, 22)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 2, 24)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 2, 28)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 2, 32)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 2, 22)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 2, 24)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 2, 46)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 2, 22)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 2, 24)) + +declare function compose(f: (a: A) => B, g: (b: B) => C): (a: A) => C; +>compose : Symbol(compose, Decl(genericContextualTypes1.ts, 2, 57)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 4, 25)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 4, 27)) +>C : Symbol(C, Decl(genericContextualTypes1.ts, 4, 30)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 4, 34)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 4, 38)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 4, 25)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 4, 27)) +>g : Symbol(g, Decl(genericContextualTypes1.ts, 4, 49)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 4, 54)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 4, 27)) +>C : Symbol(C, Decl(genericContextualTypes1.ts, 4, 30)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 4, 68)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 4, 25)) +>C : Symbol(C, Decl(genericContextualTypes1.ts, 4, 30)) + +declare function list(a: T): T[]; +>list : Symbol(list, Decl(genericContextualTypes1.ts, 4, 79)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 6, 22)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 6, 25)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 6, 22)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 6, 22)) + +declare function unlist(a: T[]): T; +>unlist : Symbol(unlist, Decl(genericContextualTypes1.ts, 6, 36)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 8, 24)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 8, 27)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 8, 24)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 8, 24)) + +declare function box(x: V): Box; +>box : Symbol(box, Decl(genericContextualTypes1.ts, 8, 38)) +>V : Symbol(V, Decl(genericContextualTypes1.ts, 10, 21)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 10, 24)) +>V : Symbol(V, Decl(genericContextualTypes1.ts, 10, 21)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>V : Symbol(V, Decl(genericContextualTypes1.ts, 10, 21)) + +declare function unbox(x: Box): W; +>unbox : Symbol(unbox, Decl(genericContextualTypes1.ts, 10, 38)) +>W : Symbol(W, Decl(genericContextualTypes1.ts, 12, 23)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 12, 26)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>W : Symbol(W, Decl(genericContextualTypes1.ts, 12, 23)) +>W : Symbol(W, Decl(genericContextualTypes1.ts, 12, 23)) + +declare function map(a: T[], f: (x: T) => U): U[]; +>map : Symbol(map, Decl(genericContextualTypes1.ts, 12, 40)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 14, 21)) +>U : Symbol(U, Decl(genericContextualTypes1.ts, 14, 23)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 14, 27)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 14, 21)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 14, 34)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 14, 39)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 14, 21)) +>U : Symbol(U, Decl(genericContextualTypes1.ts, 14, 23)) +>U : Symbol(U, Decl(genericContextualTypes1.ts, 14, 23)) + +declare function identity(x: T): T; +>identity : Symbol(identity, Decl(genericContextualTypes1.ts, 14, 56)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 16, 26)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 16, 29)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 16, 26)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 16, 26)) + +declare function zip(a: A, b: B): [A, B]; +>zip : Symbol(zip, Decl(genericContextualTypes1.ts, 16, 38)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 18, 21)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 18, 23)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 18, 27)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 18, 21)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 18, 32)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 18, 23)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 18, 21)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 18, 23)) + +declare function flip(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z; +>flip : Symbol(flip, Decl(genericContextualTypes1.ts, 18, 47)) +>X : Symbol(X, Decl(genericContextualTypes1.ts, 20, 22)) +>Y : Symbol(Y, Decl(genericContextualTypes1.ts, 20, 24)) +>Z : Symbol(Z, Decl(genericContextualTypes1.ts, 20, 27)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 20, 31)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 20, 35)) +>X : Symbol(X, Decl(genericContextualTypes1.ts, 20, 22)) +>y : Symbol(y, Decl(genericContextualTypes1.ts, 20, 40)) +>Y : Symbol(Y, Decl(genericContextualTypes1.ts, 20, 24)) +>Z : Symbol(Z, Decl(genericContextualTypes1.ts, 20, 27)) +>y : Symbol(y, Decl(genericContextualTypes1.ts, 20, 55)) +>Y : Symbol(Y, Decl(genericContextualTypes1.ts, 20, 24)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 20, 60)) +>X : Symbol(X, Decl(genericContextualTypes1.ts, 20, 22)) +>Z : Symbol(Z, Decl(genericContextualTypes1.ts, 20, 27)) + +const f00: (x: A) => A[] = list; +>f00 : Symbol(f00, Decl(genericContextualTypes1.ts, 22, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 22, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 22, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 22, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 22, 12)) +>list : Symbol(list, Decl(genericContextualTypes1.ts, 4, 79)) + +const f01: (x: A) => A[] = x => [x]; +>f01 : Symbol(f01, Decl(genericContextualTypes1.ts, 23, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 23, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 23, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 23, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 23, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 23, 29)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 23, 29)) + +const f02: (x: A) => A[] = wrap(list); +>f02 : Symbol(f02, Decl(genericContextualTypes1.ts, 24, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 24, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 24, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 24, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 24, 12)) +>wrap : Symbol(wrap, Decl(genericContextualTypes1.ts, 0, 27)) +>list : Symbol(list, Decl(genericContextualTypes1.ts, 4, 79)) + +const f03: (x: A) => A[] = wrap(x => [x]); +>f03 : Symbol(f03, Decl(genericContextualTypes1.ts, 25, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 25, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 25, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 25, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 25, 12)) +>wrap : Symbol(wrap, Decl(genericContextualTypes1.ts, 0, 27)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 25, 35)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 25, 35)) + +const f10: (x: T) => Box = compose(a => list(a), b => box(b)); +>f10 : Symbol(f10, Decl(genericContextualTypes1.ts, 27, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 27, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 27, 15)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 27, 12)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 27, 12)) +>compose : Symbol(compose, Decl(genericContextualTypes1.ts, 2, 57)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 27, 43)) +>list : Symbol(list, Decl(genericContextualTypes1.ts, 4, 79)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 27, 43)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 27, 56)) +>box : Symbol(box, Decl(genericContextualTypes1.ts, 8, 38)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 27, 56)) + +const f11: (x: T) => Box = compose(list, box); +>f11 : Symbol(f11, Decl(genericContextualTypes1.ts, 28, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 28, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 28, 15)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 28, 12)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 28, 12)) +>compose : Symbol(compose, Decl(genericContextualTypes1.ts, 2, 57)) +>list : Symbol(list, Decl(genericContextualTypes1.ts, 4, 79)) +>box : Symbol(box, Decl(genericContextualTypes1.ts, 8, 38)) + +const f12: (x: Box) => T = compose(a => unbox(a), b => unlist(b)); +>f12 : Symbol(f12, Decl(genericContextualTypes1.ts, 29, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 29, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 29, 15)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 29, 12)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 29, 12)) +>compose : Symbol(compose, Decl(genericContextualTypes1.ts, 2, 57)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 29, 43)) +>unbox : Symbol(unbox, Decl(genericContextualTypes1.ts, 10, 38)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 29, 43)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 29, 57)) +>unlist : Symbol(unlist, Decl(genericContextualTypes1.ts, 6, 36)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 29, 57)) + +const f13: (x: Box) => T = compose(unbox, unlist); +>f13 : Symbol(f13, Decl(genericContextualTypes1.ts, 30, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 30, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 30, 15)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 30, 12)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 30, 12)) +>compose : Symbol(compose, Decl(genericContextualTypes1.ts, 2, 57)) +>unbox : Symbol(unbox, Decl(genericContextualTypes1.ts, 10, 38)) +>unlist : Symbol(unlist, Decl(genericContextualTypes1.ts, 6, 36)) + +const arrayMap = (f: (x: T) => U) => (a: T[]) => a.map(f); +>arrayMap : Symbol(arrayMap, Decl(genericContextualTypes1.ts, 32, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 32, 18)) +>U : Symbol(U, Decl(genericContextualTypes1.ts, 32, 20)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 32, 24)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 32, 28)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 32, 18)) +>U : Symbol(U, Decl(genericContextualTypes1.ts, 32, 20)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 32, 44)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 32, 18)) +>a.map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 32, 44)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 32, 24)) + +const arrayFilter = (f: (x: T) => boolean) => (a: T[]) => a.filter(f); +>arrayFilter : Symbol(arrayFilter, Decl(genericContextualTypes1.ts, 33, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 33, 21)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 33, 24)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 33, 28)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 33, 21)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 33, 50)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 33, 21)) +>a.filter : Symbol(Array.filter, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 33, 50)) +>filter : Symbol(Array.filter, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 33, 24)) + +const f20: (a: string[]) => number[] = arrayMap(x => x.length); +>f20 : Symbol(f20, Decl(genericContextualTypes1.ts, 35, 5)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 35, 12)) +>arrayMap : Symbol(arrayMap, Decl(genericContextualTypes1.ts, 32, 5)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 35, 48)) +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 35, 48)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + +const f21: (a: A[]) => A[][] = arrayMap(x => [x]); +>f21 : Symbol(f21, Decl(genericContextualTypes1.ts, 36, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 36, 12)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 36, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 36, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 36, 12)) +>arrayMap : Symbol(arrayMap, Decl(genericContextualTypes1.ts, 32, 5)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 36, 43)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 36, 43)) + +const f22: (a: A[]) => A[] = arrayMap(identity); +>f22 : Symbol(f22, Decl(genericContextualTypes1.ts, 37, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 37, 12)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 37, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 37, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 37, 12)) +>arrayMap : Symbol(arrayMap, Decl(genericContextualTypes1.ts, 32, 5)) +>identity : Symbol(identity, Decl(genericContextualTypes1.ts, 14, 56)) + +const f23: (a: A[]) => Box[] = arrayMap(value => ({ value })); +>f23 : Symbol(f23, Decl(genericContextualTypes1.ts, 38, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 38, 12)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 38, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 38, 12)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 38, 12)) +>arrayMap : Symbol(arrayMap, Decl(genericContextualTypes1.ts, 32, 5)) +>value : Symbol(value, Decl(genericContextualTypes1.ts, 38, 46)) +>value : Symbol(value, Decl(genericContextualTypes1.ts, 38, 57)) + +const f30: (a: string[]) => string[] = arrayFilter(x => x.length > 10); +>f30 : Symbol(f30, Decl(genericContextualTypes1.ts, 40, 5)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 40, 12)) +>arrayFilter : Symbol(arrayFilter, Decl(genericContextualTypes1.ts, 33, 5)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 40, 51)) +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 40, 51)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + +const f31: >(a: T[]) => T[] = arrayFilter(x => x.value > 10); +>f31 : Symbol(f31, Decl(genericContextualTypes1.ts, 41, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 41, 12)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 41, 35)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 41, 12)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 41, 12)) +>arrayFilter : Symbol(arrayFilter, Decl(genericContextualTypes1.ts, 33, 5)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 41, 64)) +>x.value : Symbol(value, Decl(genericContextualTypes1.ts, 0, 15)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 41, 64)) +>value : Symbol(value, Decl(genericContextualTypes1.ts, 0, 15)) + +const f40: (b: B, a: A) => [A, B] = flip(zip); +>f40 : Symbol(f40, Decl(genericContextualTypes1.ts, 43, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 43, 12)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 43, 14)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 43, 18)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 43, 14)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 43, 23)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 43, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 43, 12)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 43, 14)) +>flip : Symbol(flip, Decl(genericContextualTypes1.ts, 18, 47)) +>zip : Symbol(zip, Decl(genericContextualTypes1.ts, 16, 38)) + +// Repro from #16293 + +type fn = (a: A) => A; +>fn : Symbol(fn, Decl(genericContextualTypes1.ts, 43, 52), Decl(genericContextualTypes1.ts, 48, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 47, 11)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 47, 14)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 47, 11)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 47, 11)) + +const fn: fn = a => a; +>fn : Symbol(fn, Decl(genericContextualTypes1.ts, 43, 52), Decl(genericContextualTypes1.ts, 48, 5)) +>fn : Symbol(fn, Decl(genericContextualTypes1.ts, 43, 52), Decl(genericContextualTypes1.ts, 48, 5)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 48, 14)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 48, 14)) + diff --git a/tests/baselines/reference/genericContextualTypes1.types b/tests/baselines/reference/genericContextualTypes1.types new file mode 100644 index 00000000000..843591bbd10 --- /dev/null +++ b/tests/baselines/reference/genericContextualTypes1.types @@ -0,0 +1,362 @@ +=== tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts === +type Box = { value: T }; +>Box : Box +>T : T +>value : T +>T : T + +declare function wrap(f: (a: A) => B): (a: A) => B; +>wrap : (f: (a: A) => B) => (a: A) => B +>A : A +>B : B +>f : (a: A) => B +>a : A +>A : A +>B : B +>a : A +>A : A +>B : B + +declare function compose(f: (a: A) => B, g: (b: B) => C): (a: A) => C; +>compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C +>A : A +>B : B +>C : C +>f : (a: A) => B +>a : A +>A : A +>B : B +>g : (b: B) => C +>b : B +>B : B +>C : C +>a : A +>A : A +>C : C + +declare function list(a: T): T[]; +>list : (a: T) => T[] +>T : T +>a : T +>T : T +>T : T + +declare function unlist(a: T[]): T; +>unlist : (a: T[]) => T +>T : T +>a : T[] +>T : T +>T : T + +declare function box(x: V): Box; +>box : (x: V) => Box +>V : V +>x : V +>V : V +>Box : Box +>V : V + +declare function unbox(x: Box): W; +>unbox : (x: Box) => W +>W : W +>x : Box +>Box : Box +>W : W +>W : W + +declare function map(a: T[], f: (x: T) => U): U[]; +>map : (a: T[], f: (x: T) => U) => U[] +>T : T +>U : U +>a : T[] +>T : T +>f : (x: T) => U +>x : T +>T : T +>U : U +>U : U + +declare function identity(x: T): T; +>identity : (x: T) => T +>T : T +>x : T +>T : T +>T : T + +declare function zip(a: A, b: B): [A, B]; +>zip : (a: A, b: B) => [A, B] +>A : A +>B : B +>a : A +>A : A +>b : B +>B : B +>A : A +>B : B + +declare function flip(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z; +>flip : (f: (x: X, y: Y) => Z) => (y: Y, x: X) => Z +>X : X +>Y : Y +>Z : Z +>f : (x: X, y: Y) => Z +>x : X +>X : X +>y : Y +>Y : Y +>Z : Z +>y : Y +>Y : Y +>x : X +>X : X +>Z : Z + +const f00: (x: A) => A[] = list; +>f00 : (x: A) => A[] +>A : A +>x : A +>A : A +>A : A +>list : (a: T) => T[] + +const f01: (x: A) => A[] = x => [x]; +>f01 : (x: A) => A[] +>A : A +>x : A +>A : A +>A : A +>x => [x] : (x: A) => A[] +>x : A +>[x] : A[] +>x : A + +const f02: (x: A) => A[] = wrap(list); +>f02 : (x: A) => A[] +>A : A +>x : A +>A : A +>A : A +>wrap(list) : (a: A) => A[] +>wrap : (f: (a: A) => B) => (a: A) => B +>list : (a: T) => T[] + +const f03: (x: A) => A[] = wrap(x => [x]); +>f03 : (x: A) => A[] +>A : A +>x : A +>A : A +>A : A +>wrap(x => [x]) : (a: A) => A[] +>wrap : (f: (a: A) => B) => (a: A) => B +>x => [x] : (x: A) => A[] +>x : A +>[x] : A[] +>x : A + +const f10: (x: T) => Box = compose(a => list(a), b => box(b)); +>f10 : (x: T) => Box +>T : T +>x : T +>T : T +>Box : Box +>T : T +>compose(a => list(a), b => box(b)) : (a: T) => Box +>compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C +>a => list(a) : (a: T) => T[] +>a : T +>list(a) : T[] +>list : (a: T) => T[] +>a : T +>b => box(b) : (b: T[]) => Box +>b : T[] +>box(b) : Box +>box : (x: V) => Box +>b : T[] + +const f11: (x: T) => Box = compose(list, box); +>f11 : (x: T) => Box +>T : T +>x : T +>T : T +>Box : Box +>T : T +>compose(list, box) : (a: T) => Box +>compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C +>list : (a: T) => T[] +>box : (x: V) => Box + +const f12: (x: Box) => T = compose(a => unbox(a), b => unlist(b)); +>f12 : (x: Box) => T +>T : T +>x : Box +>Box : Box +>T : T +>T : T +>compose(a => unbox(a), b => unlist(b)) : (a: Box) => T +>compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C +>a => unbox(a) : (a: Box) => T[] +>a : Box +>unbox(a) : T[] +>unbox : (x: Box) => W +>a : Box +>b => unlist(b) : (b: T[]) => T +>b : T[] +>unlist(b) : T +>unlist : (a: T[]) => T +>b : T[] + +const f13: (x: Box) => T = compose(unbox, unlist); +>f13 : (x: Box) => T +>T : T +>x : Box +>Box : Box +>T : T +>T : T +>compose(unbox, unlist) : (a: Box) => T +>compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C +>unbox : (x: Box) => W +>unlist : (a: T[]) => T + +const arrayMap = (f: (x: T) => U) => (a: T[]) => a.map(f); +>arrayMap : (f: (x: T) => U) => (a: T[]) => U[] +>(f: (x: T) => U) => (a: T[]) => a.map(f) : (f: (x: T) => U) => (a: T[]) => U[] +>T : T +>U : U +>f : (x: T) => U +>x : T +>T : T +>U : U +>(a: T[]) => a.map(f) : (a: T[]) => U[] +>a : T[] +>T : T +>a.map(f) : U[] +>a.map : { (this: [T, T, T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U): [U, U, U, U, U]; (this: [T, T, T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U, thisArg: undefined): [U, U, U, U, U]; (this: [T, T, T, T, T], callbackfn: (this: Z, value: T, index: number, array: T[]) => U, thisArg: Z): [U, U, U, U, U]; (this: [T, T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U): [U, U, U, U]; (this: [T, T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U, thisArg: undefined): [U, U, U, U]; (this: [T, T, T, T], callbackfn: (this: Z, value: T, index: number, array: T[]) => U, thisArg: Z): [U, U, U, U]; (this: [T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U): [U, U, U]; (this: [T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U, thisArg: undefined): [U, U, U]; (this: [T, T, T], callbackfn: (this: Z, value: T, index: number, array: T[]) => U, thisArg: Z): [U, U, U]; (this: [T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U): [U, U]; (this: [T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U, thisArg: undefined): [U, U]; (this: [T, T], callbackfn: (this: Z, value: T, index: number, array: T[]) => U, thisArg: Z): [U, U]; (callbackfn: (this: void, value: T, index: number, array: T[]) => U): U[]; (callbackfn: (this: void, value: T, index: number, array: T[]) => U, thisArg: undefined): U[]; (callbackfn: (this: Z, value: T, index: number, array: T[]) => U, thisArg: Z): U[]; } +>a : T[] +>map : { (this: [T, T, T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U): [U, U, U, U, U]; (this: [T, T, T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U, thisArg: undefined): [U, U, U, U, U]; (this: [T, T, T, T, T], callbackfn: (this: Z, value: T, index: number, array: T[]) => U, thisArg: Z): [U, U, U, U, U]; (this: [T, T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U): [U, U, U, U]; (this: [T, T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U, thisArg: undefined): [U, U, U, U]; (this: [T, T, T, T], callbackfn: (this: Z, value: T, index: number, array: T[]) => U, thisArg: Z): [U, U, U, U]; (this: [T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U): [U, U, U]; (this: [T, T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U, thisArg: undefined): [U, U, U]; (this: [T, T, T], callbackfn: (this: Z, value: T, index: number, array: T[]) => U, thisArg: Z): [U, U, U]; (this: [T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U): [U, U]; (this: [T, T], callbackfn: (this: void, value: T, index: number, array: T[]) => U, thisArg: undefined): [U, U]; (this: [T, T], callbackfn: (this: Z, value: T, index: number, array: T[]) => U, thisArg: Z): [U, U]; (callbackfn: (this: void, value: T, index: number, array: T[]) => U): U[]; (callbackfn: (this: void, value: T, index: number, array: T[]) => U, thisArg: undefined): U[]; (callbackfn: (this: Z, value: T, index: number, array: T[]) => U, thisArg: Z): U[]; } +>f : (x: T) => U + +const arrayFilter = (f: (x: T) => boolean) => (a: T[]) => a.filter(f); +>arrayFilter : (f: (x: T) => boolean) => (a: T[]) => T[] +>(f: (x: T) => boolean) => (a: T[]) => a.filter(f) : (f: (x: T) => boolean) => (a: T[]) => T[] +>T : T +>f : (x: T) => boolean +>x : T +>T : T +>(a: T[]) => a.filter(f) : (a: T[]) => T[] +>a : T[] +>T : T +>a.filter(f) : T[] +>a.filter : { (callbackfn: (this: void, value: T, index: number, array: T[]) => any): T[]; (callbackfn: (this: void, value: T, index: number, array: T[]) => any, thisArg: undefined): T[]; (callbackfn: (this: Z, value: T, index: number, array: T[]) => any, thisArg: Z): T[]; } +>a : T[] +>filter : { (callbackfn: (this: void, value: T, index: number, array: T[]) => any): T[]; (callbackfn: (this: void, value: T, index: number, array: T[]) => any, thisArg: undefined): T[]; (callbackfn: (this: Z, value: T, index: number, array: T[]) => any, thisArg: Z): T[]; } +>f : (x: T) => boolean + +const f20: (a: string[]) => number[] = arrayMap(x => x.length); +>f20 : (a: string[]) => number[] +>a : string[] +>arrayMap(x => x.length) : (a: string[]) => number[] +>arrayMap : (f: (x: T) => U) => (a: T[]) => U[] +>x => x.length : (x: string) => number +>x : string +>x.length : number +>x : string +>length : number + +const f21: (a: A[]) => A[][] = arrayMap(x => [x]); +>f21 : (a: A[]) => A[][] +>A : A +>a : A[] +>A : A +>A : A +>arrayMap(x => [x]) : (a: A[]) => A[][] +>arrayMap : (f: (x: T) => U) => (a: T[]) => U[] +>x => [x] : (x: A) => A[] +>x : A +>[x] : A[] +>x : A + +const f22: (a: A[]) => A[] = arrayMap(identity); +>f22 : (a: A[]) => A[] +>A : A +>a : A[] +>A : A +>A : A +>arrayMap(identity) : (a: A[]) => A[] +>arrayMap : (f: (x: T) => U) => (a: T[]) => U[] +>identity : (x: T) => T + +const f23: (a: A[]) => Box[] = arrayMap(value => ({ value })); +>f23 : (a: A[]) => Box[] +>A : A +>a : A[] +>A : A +>Box : Box +>A : A +>arrayMap(value => ({ value })) : (a: A[]) => { value: A; }[] +>arrayMap : (f: (x: T) => U) => (a: T[]) => U[] +>value => ({ value }) : (value: A) => { value: A; } +>value : A +>({ value }) : { value: A; } +>{ value } : { value: A; } +>value : A + +const f30: (a: string[]) => string[] = arrayFilter(x => x.length > 10); +>f30 : (a: string[]) => string[] +>a : string[] +>arrayFilter(x => x.length > 10) : (a: string[]) => string[] +>arrayFilter : (f: (x: T) => boolean) => (a: T[]) => T[] +>x => x.length > 10 : (x: string) => boolean +>x : string +>x.length > 10 : boolean +>x.length : number +>x : string +>length : number +>10 : 10 + +const f31: >(a: T[]) => T[] = arrayFilter(x => x.value > 10); +>f31 : >(a: T[]) => T[] +>T : T +>Box : Box +>a : T[] +>T : T +>T : T +>arrayFilter(x => x.value > 10) : (a: T[]) => T[] +>arrayFilter : (f: (x: T) => boolean) => (a: T[]) => T[] +>x => x.value > 10 : (x: T) => boolean +>x : T +>x.value > 10 : boolean +>x.value : number +>x : T +>value : number +>10 : 10 + +const f40: (b: B, a: A) => [A, B] = flip(zip); +>f40 : (b: B, a: A) => [A, B] +>A : A +>B : B +>b : B +>B : B +>a : A +>A : A +>A : A +>B : B +>flip(zip) : (y: B, x: A) => [A, B] +>flip : (f: (x: X, y: Y) => Z) => (y: Y, x: X) => Z +>zip : (a: A, b: B) => [A, B] + +// Repro from #16293 + +type fn = (a: A) => A; +>fn : fn +>A : A +>a : A +>A : A +>A : A + +const fn: fn = a => a; +>fn : fn +>fn : fn +>a => a : (a: A) => A +>a : A +>a : A + diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts new file mode 100644 index 00000000000..6d937adcbf6 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts @@ -0,0 +1,52 @@ +// @strict: true +// @declaration: true + +type Box = { value: T }; + +declare function wrap(f: (a: A) => B): (a: A) => B; + +declare function compose(f: (a: A) => B, g: (b: B) => C): (a: A) => C; + +declare function list(a: T): T[]; + +declare function unlist(a: T[]): T; + +declare function box(x: V): Box; + +declare function unbox(x: Box): W; + +declare function map(a: T[], f: (x: T) => U): U[]; + +declare function identity(x: T): T; + +declare function zip(a: A, b: B): [A, B]; + +declare function flip(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z; + +const f00: (x: A) => A[] = list; +const f01: (x: A) => A[] = x => [x]; +const f02: (x: A) => A[] = wrap(list); +const f03: (x: A) => A[] = wrap(x => [x]); + +const f10: (x: T) => Box = compose(a => list(a), b => box(b)); +const f11: (x: T) => Box = compose(list, box); +const f12: (x: Box) => T = compose(a => unbox(a), b => unlist(b)); +const f13: (x: Box) => T = compose(unbox, unlist); + +const arrayMap = (f: (x: T) => U) => (a: T[]) => a.map(f); +const arrayFilter = (f: (x: T) => boolean) => (a: T[]) => a.filter(f); + +const f20: (a: string[]) => number[] = arrayMap(x => x.length); +const f21: (a: A[]) => A[][] = arrayMap(x => [x]); +const f22: (a: A[]) => A[] = arrayMap(identity); +const f23: (a: A[]) => Box[] = arrayMap(value => ({ value })); + +const f30: (a: string[]) => string[] = arrayFilter(x => x.length > 10); +const f31: >(a: T[]) => T[] = arrayFilter(x => x.value > 10); + +const f40: (b: B, a: A) => [A, B] = flip(zip); + +// Repro from #16293 + +type fn = (a: A) => A; +const fn: fn = a => a; From 8cb5333791b386d497da316ea694f9f976fdc403 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 6 Jun 2017 13:33:19 -0700 Subject: [PATCH 017/138] Verify JS function is constructor --- Jakefile.js | 7 ++++--- src/compiler/checker.ts | 22 +++++++++++++++++++++- src/compiler/parser.ts | 11 +++++++++++ src/compiler/types.ts | 5 +++++ src/compiler/utilities.ts | 4 ++++ 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 439fced0720..274c80cea24 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -802,7 +802,8 @@ function runConsoleTests(defaultReporter, runInParallel) { var debug = process.env.debug || process.env.d; var inspect = process.env.inspect; - tests = process.env.test || process.env.tests || process.env.t; + var testTimeout = process.env.timeout || defaultTestTimeout; + var tests = process.env.test || process.env.tests || process.env.t; var light = process.env.light || false; var stackTraceLimit = process.env.stackTraceLimit; var testConfigFile = 'test.config'; @@ -820,7 +821,7 @@ function runConsoleTests(defaultReporter, runInParallel) { } while (fs.existsSync(taskConfigsFolder)); fs.mkdirSync(taskConfigsFolder); - workerCount = process.env.workerCount || os.cpus().length; + workerCount = process.env.workerCount || process.env.p || os.cpus().length; } if (tests || light || taskConfigsFolder) { @@ -925,7 +926,7 @@ function runConsoleTests(defaultReporter, runInParallel) { } } -var testTimeout = 20000; +var defaultTestTimeout = 20000; 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); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6188f1aead9..b1a836fe865 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15892,7 +15892,7 @@ namespace ts { const callSignatures = getSignaturesOfType(expressionType, SignatureKind.Call); if (callSignatures.length) { const signature = resolveCall(node, callSignatures, candidatesOutArray); - if (!isInJavaScriptFile(signature.declaration) && getReturnTypeOfSignature(signature) !== voidType) { + if (!isJavaScriptConstructor(signature.declaration) && getReturnTypeOfSignature(signature) !== voidType) { error(node, Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } if (getThisTypeOfSignature(signature) === voidType) { @@ -16119,6 +16119,26 @@ namespace ts { return getNodeLinks(node).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(node); } + /** + * Indicates whether a declaration can be treated as a constructor in a JavaScript + * file. + */ + function isJavaScriptConstructor(node: Declaration): boolean { + if (isInJavaScriptFile(node)) { + // If the node has a @class tag, treat it like a constructor. + if (getJSDocClassTag(node)) return true; + + // If the symbol of the node has members, treat it like a constructor. + const symbol = isFunctionDeclaration(node) || isFunctionExpression(node) ? getSymbolOfNode(node) : + isVariableDeclaration(node) && isFunctionExpression(node.initializer) ? getSymbolOfNode(node.initializer) : + undefined; + + return symbol && symbol.members !== undefined; + } + + return false; + } + function getInferredClassType(symbol: Symbol) { const links = getSymbolLinks(symbol); if (!links.inferredClassType) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 84306cd81d8..b398ee66e0a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6533,6 +6533,10 @@ namespace ts { case "augments": tag = parseAugmentsTag(atToken, tagName); break; + case "class": + case "constructor": + tag = parseClassTag(atToken, tagName); + break; case "arg": case "argument": case "param": @@ -6752,6 +6756,13 @@ namespace ts { return finishNode(result); } + function parseClassTag(atToken: AtToken, tagName: Identifier): JSDocClassTag { + const tag = createNode(SyntaxKind.JSDocClassTag, atToken.pos); + tag.atToken = atToken; + tag.tagName = tagName; + return finishNode(tag); + } + function parseTypedefTag(atToken: AtToken, tagName: Identifier): JSDocTypedefTag { const typeExpression = tryParseTypeExpression(); skipWhitespace(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1c7f36bb27b..ab04f72faf0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -374,6 +374,7 @@ namespace ts { JSDocComment, JSDocTag, JSDocAugmentsTag, + JSDocClassTag, JSDocParameterTag, JSDocReturnTag, JSDocTypeTag, @@ -2132,6 +2133,10 @@ namespace ts { typeExpression: JSDocTypeExpression; } + export interface JSDocClassTag extends JSDocTag { + kind: SyntaxKind.JSDocClassTag; + } + export interface JSDocTemplateTag extends JSDocTag { kind: SyntaxKind.JSDocTemplateTag; typeParameters: NodeArray; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 30f7e0a52f9..77f1e43c9cb 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1562,6 +1562,10 @@ namespace ts { return getFirstJSDocTag(node, SyntaxKind.JSDocAugmentsTag) as JSDocAugmentsTag; } + export function getJSDocClassTag(node: Node): JSDocClassTag { + return getFirstJSDocTag(node, SyntaxKind.JSDocClassTag) as JSDocClassTag; + } + export function getJSDocReturnTag(node: Node): JSDocReturnTag { return getFirstJSDocTag(node, SyntaxKind.JSDocReturnTag) as JSDocReturnTag; } From 34710a33b5a8f18f1cdc9fa9ec728968e6e16c1e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 6 Jun 2017 13:35:29 -0700 Subject: [PATCH 018/138] Fix fourslash tests --- .../contextualTypingOfGenericCallSignatures2.ts | 2 +- .../contextuallyTypedFunctionExpressionGeneric1.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts b/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts index 7bc95085e22..efb26cb3af1 100644 --- a/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts +++ b/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts @@ -7,5 +7,5 @@ ////// x should not be contextually typed so this should be an error ////f6(/**/x => x()) -verify.quickInfoAt("", "(parameter) x: T extends T"); +verify.quickInfoAt("", "(parameter) x: T extends I"); verify.numberOfErrorsInCurrentFile(1); diff --git a/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts b/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts index 7337a429d9c..bfc4d7ea6fd 100644 --- a/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts +++ b/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts @@ -1,13 +1,13 @@ /// -interface Comparable { - compareTo(other: T): T; -} -interface Comparer { - >(x: T, y: T): T; -} +////interface Comparable { +//// compareTo(other: T): T; +////} +////interface Comparer { +//// >(x: T, y: T): T; +////} -//var max2: Comparer = (x/*1*/x, y/*2*/y) => { return x/*3*/x.compareTo(y/*4*/y) }; +////var max2: Comparer = (x/*1*/x, y/*2*/y) => { return x/*3*/x.compareTo(y/*4*/y) }; verify.quickInfos({ 1: "(parameter) xx: T extends Comparable", From ea830d4fad5c7a9fec4d1403fe047cb1fccb4db5 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 6 Jun 2017 13:58:54 -0700 Subject: [PATCH 019/138] Move spreadUnion* tests into conformance suite --- tests/cases/{compiler => conformance/types/spread}/spreadUnion.ts | 0 .../cases/{compiler => conformance/types/spread}/spreadUnion2.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/cases/{compiler => conformance/types/spread}/spreadUnion.ts (100%) rename tests/cases/{compiler => conformance/types/spread}/spreadUnion2.ts (100%) diff --git a/tests/cases/compiler/spreadUnion.ts b/tests/cases/conformance/types/spread/spreadUnion.ts similarity index 100% rename from tests/cases/compiler/spreadUnion.ts rename to tests/cases/conformance/types/spread/spreadUnion.ts diff --git a/tests/cases/compiler/spreadUnion2.ts b/tests/cases/conformance/types/spread/spreadUnion2.ts similarity index 100% rename from tests/cases/compiler/spreadUnion2.ts rename to tests/cases/conformance/types/spread/spreadUnion2.ts From de3ff39a022269526b565837e844fdd024f613cf Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 6 Jun 2017 14:07:04 -0700 Subject: [PATCH 020/138] Accept new baselines --- ...gnmentCompatWithCallSignatures3.errors.txt | 123 ++- ...gnmentCompatWithCallSignatures4.errors.txt | 119 ++- ...gnmentCompatWithCallSignatures5.errors.txt | 93 ++ ...gnmentCompatWithCallSignatures6.errors.txt | 61 ++ ...tCompatWithConstructSignatures3.errors.txt | 123 ++- ...tCompatWithConstructSignatures4.errors.txt | 119 ++- ...tCompatWithConstructSignatures5.errors.txt | 93 ++ ...tCompatWithConstructSignatures6.errors.txt | 61 ++ ...ompatWithGenericCallSignatures2.errors.txt | 27 + ...ompatWithGenericCallSignatures4.errors.txt | 27 + ...ignaturesWithOptionalParameters.errors.txt | 149 ++- .../assignmentStricterConstraints.errors.txt | 19 + .../asyncFunctionDeclaration15_es5.errors.txt | 12 +- ...atureAssignabilityInInheritance.errors.txt | 11 +- ...tureAssignabilityInInheritance3.errors.txt | 50 +- ...tureAssignabilityInInheritance6.errors.txt | 142 +++ ...atureAssignabilityInInheritance.errors.txt | 11 +- ...tureAssignabilityInInheritance3.errors.txt | 50 +- ...tureAssignabilityInInheritance6.errors.txt | 142 +++ ...ionTypeArgumentAssignmentCompat.errors.txt | 7 +- ...ArgumentCallSigAssignmentCompat.errors.txt | 30 + ...mentCompatOfFunctionSignatures1.errors.txt | 34 + ...CallSignatureReturnTypeMismatch.errors.txt | 7 +- .../reference/genericImplements.errors.txt | 32 + .../genericSpecializations1.errors.txt | 40 + .../genericSpecializations2.errors.txt | 24 +- .../genericTypeArgumentInference1.errors.txt | 26 + .../mismatchedGenericArguments1.errors.txt | 40 + .../reference/promiseTypeInference.errors.txt | 31 + .../subtypingWithCallSignatures2.types | 156 +-- .../subtypingWithCallSignatures3.types | 80 +- .../subtypingWithCallSignatures4.types | 16 +- ...aturesWithSpecializedSignatures.errors.txt | 11 +- .../subtypingWithConstructSignatures2.types | 144 +-- .../subtypingWithConstructSignatures3.types | 80 +- .../subtypingWithConstructSignatures4.types | 16 +- ...btypingWithConstructSignatures6.errors.txt | 142 +++ ...aturesWithSpecializedSignatures.errors.txt | 11 +- ...ignaturesWithOptionalParameters.errors.txt | 166 +++- ...ignaturesWithOptionalParameters.errors.txt | 166 +++- ...ConstrainedToOuterTypeParameter.errors.txt | 22 + .../reference/underscoreTest1.errors.txt | 908 ++++++++++++++++++ 42 files changed, 3319 insertions(+), 302 deletions(-) create mode 100644 tests/baselines/reference/assignmentCompatWithCallSignatures5.errors.txt create mode 100644 tests/baselines/reference/assignmentCompatWithCallSignatures6.errors.txt create mode 100644 tests/baselines/reference/assignmentCompatWithConstructSignatures5.errors.txt create mode 100644 tests/baselines/reference/assignmentCompatWithConstructSignatures6.errors.txt create mode 100644 tests/baselines/reference/assignmentCompatWithGenericCallSignatures2.errors.txt create mode 100644 tests/baselines/reference/assignmentCompatWithGenericCallSignatures4.errors.txt create mode 100644 tests/baselines/reference/assignmentStricterConstraints.errors.txt create mode 100644 tests/baselines/reference/callSignatureAssignabilityInInheritance6.errors.txt create mode 100644 tests/baselines/reference/constructSignatureAssignabilityInInheritance6.errors.txt create mode 100644 tests/baselines/reference/genericArgumentCallSigAssignmentCompat.errors.txt create mode 100644 tests/baselines/reference/genericAssignmentCompatOfFunctionSignatures1.errors.txt create mode 100644 tests/baselines/reference/genericImplements.errors.txt create mode 100644 tests/baselines/reference/genericSpecializations1.errors.txt create mode 100644 tests/baselines/reference/genericTypeArgumentInference1.errors.txt create mode 100644 tests/baselines/reference/mismatchedGenericArguments1.errors.txt create mode 100644 tests/baselines/reference/promiseTypeInference.errors.txt create mode 100644 tests/baselines/reference/subtypingWithConstructSignatures6.errors.txt create mode 100644 tests/baselines/reference/typeParameterConstrainedToOuterTypeParameter.errors.txt create mode 100644 tests/baselines/reference/underscoreTest1.errors.txt 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/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/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/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/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/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/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/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/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/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: '