From 96937fd59277d8084f1c2ae51fdbf1e144e8c86c Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 19 Nov 2018 17:05:28 -0800 Subject: [PATCH] Allow union signatures to merge when they have differing argument counts (#28604) * Allow union signatures to merge when they have differing argument counts * Accept updated baselines * Adjust comments io changed tests --- src/compiler/checker.ts | 9 +-- .../reactSFCAndFunctionResolvable.js | 41 +++++++++++ .../reactSFCAndFunctionResolvable.symbols | 67 ++++++++++++++++++ .../reactSFCAndFunctionResolvable.types | 69 +++++++++++++++++++ .../unionTypeCallSignatures.errors.txt | 62 +++++++---------- .../reference/unionTypeCallSignatures.js | 28 ++++---- .../reference/unionTypeCallSignatures.symbols | 14 ++-- .../reference/unionTypeCallSignatures.types | 28 ++++---- .../unionTypeCallSignatures4.errors.txt | 12 +--- .../reference/unionTypeCallSignatures4.js | 8 +-- .../unionTypeCallSignatures4.symbols | 4 +- .../reference/unionTypeCallSignatures4.types | 8 +-- .../unionTypeConstructSignatures.errors.txt | 64 ++++++++--------- .../reference/unionTypeConstructSignatures.js | 32 ++++----- .../unionTypeConstructSignatures.symbols | 16 ++--- .../unionTypeConstructSignatures.types | 30 ++++---- .../reactSFCAndFunctionResolvable.tsx | 25 +++++++ .../types/union/unionTypeCallSignatures.ts | 14 ++-- .../types/union/unionTypeCallSignatures4.ts | 4 +- .../union/unionTypeConstructSignatures.ts | 16 ++--- .../completionEntryForUnionProperty2.ts | 2 +- 21 files changed, 362 insertions(+), 191 deletions(-) create mode 100644 tests/baselines/reference/reactSFCAndFunctionResolvable.js create mode 100644 tests/baselines/reference/reactSFCAndFunctionResolvable.symbols create mode 100644 tests/baselines/reference/reactSFCAndFunctionResolvable.types create mode 100644 tests/cases/compiler/reactSFCAndFunctionResolvable.tsx diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e4090f7d8c3..6ef51bc401a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13105,13 +13105,8 @@ namespace ts { return true; } // A source signature partially matches a target signature if the target signature has no fewer required - // parameters and no more overall parameters than the source signature (where a signature with a rest - // parameter is always considered to have more overall parameters than one without). - const sourceRestCount = sourceHasRestParameter ? 1 : 0; - const targetRestCount = targetHasRestParameter ? 1 : 0; - if (partialMatch && sourceMinArgumentCount <= targetMinArgumentCount && ( - sourceRestCount > targetRestCount || - sourceRestCount === targetRestCount && sourceParameterCount >= targetParameterCount)) { + // parameters + if (partialMatch && sourceMinArgumentCount <= targetMinArgumentCount) { return true; } return false; diff --git a/tests/baselines/reference/reactSFCAndFunctionResolvable.js b/tests/baselines/reference/reactSFCAndFunctionResolvable.js new file mode 100644 index 00000000000..a949f132170 --- /dev/null +++ b/tests/baselines/reference/reactSFCAndFunctionResolvable.js @@ -0,0 +1,41 @@ +//// [reactSFCAndFunctionResolvable.tsx] +/// + +import * as React from 'react'; + +declare const Radio: (props: {}) => React.ReactElement<{}>; +declare const OtherRadio: () => React.ReactElement<{}>; +declare const Checkbox: React.SFC; + +declare const condition1: boolean; +declare const condition2: boolean; +declare const condition3: boolean; + +const RandomComponent: React.SFC = () => { + const Component = + condition1 + ? Radio + : Checkbox; + + const OtherComponent = + condition2 + ? OtherRadio + : Checkbox; + return condition1 ? : ; +}; + + +//// [reactSFCAndFunctionResolvable.js] +"use strict"; +/// +exports.__esModule = true; +var React = require("react"); +var RandomComponent = function () { + var Component = condition1 + ? Radio + : Checkbox; + var OtherComponent = condition2 + ? OtherRadio + : Checkbox; + return condition1 ? React.createElement(Component, null) : React.createElement(OtherComponent, null); +}; diff --git a/tests/baselines/reference/reactSFCAndFunctionResolvable.symbols b/tests/baselines/reference/reactSFCAndFunctionResolvable.symbols new file mode 100644 index 00000000000..18231fa8b60 --- /dev/null +++ b/tests/baselines/reference/reactSFCAndFunctionResolvable.symbols @@ -0,0 +1,67 @@ +=== tests/cases/compiler/reactSFCAndFunctionResolvable.tsx === +/// + +import * as React from 'react'; +>React : Symbol(React, Decl(reactSFCAndFunctionResolvable.tsx, 2, 6)) + +declare const Radio: (props: {}) => React.ReactElement<{}>; +>Radio : Symbol(Radio, Decl(reactSFCAndFunctionResolvable.tsx, 4, 13)) +>props : Symbol(props, Decl(reactSFCAndFunctionResolvable.tsx, 4, 22)) +>React : Symbol(React, Decl(reactSFCAndFunctionResolvable.tsx, 2, 6)) +>ReactElement : Symbol(React.ReactElement, Decl(react16.d.ts, 135, 9)) + +declare const OtherRadio: () => React.ReactElement<{}>; +>OtherRadio : Symbol(OtherRadio, Decl(reactSFCAndFunctionResolvable.tsx, 5, 13)) +>React : Symbol(React, Decl(reactSFCAndFunctionResolvable.tsx, 2, 6)) +>ReactElement : Symbol(React.ReactElement, Decl(react16.d.ts, 135, 9)) + +declare const Checkbox: React.SFC; +>Checkbox : Symbol(Checkbox, Decl(reactSFCAndFunctionResolvable.tsx, 6, 13)) +>React : Symbol(React, Decl(reactSFCAndFunctionResolvable.tsx, 2, 6)) +>SFC : Symbol(React.SFC, Decl(react16.d.ts, 400, 9)) + +declare const condition1: boolean; +>condition1 : Symbol(condition1, Decl(reactSFCAndFunctionResolvable.tsx, 8, 13)) + +declare const condition2: boolean; +>condition2 : Symbol(condition2, Decl(reactSFCAndFunctionResolvable.tsx, 9, 13)) + +declare const condition3: boolean; +>condition3 : Symbol(condition3, Decl(reactSFCAndFunctionResolvable.tsx, 10, 13)) + +const RandomComponent: React.SFC = () => { +>RandomComponent : Symbol(RandomComponent, Decl(reactSFCAndFunctionResolvable.tsx, 12, 5)) +>React : Symbol(React, Decl(reactSFCAndFunctionResolvable.tsx, 2, 6)) +>SFC : Symbol(React.SFC, Decl(react16.d.ts, 400, 9)) + + const Component = +>Component : Symbol(Component, Decl(reactSFCAndFunctionResolvable.tsx, 13, 7)) + + condition1 +>condition1 : Symbol(condition1, Decl(reactSFCAndFunctionResolvable.tsx, 8, 13)) + + ? Radio +>Radio : Symbol(Radio, Decl(reactSFCAndFunctionResolvable.tsx, 4, 13)) + + : Checkbox; +>Checkbox : Symbol(Checkbox, Decl(reactSFCAndFunctionResolvable.tsx, 6, 13)) + + const OtherComponent = +>OtherComponent : Symbol(OtherComponent, Decl(reactSFCAndFunctionResolvable.tsx, 18, 7)) + + condition2 +>condition2 : Symbol(condition2, Decl(reactSFCAndFunctionResolvable.tsx, 9, 13)) + + ? OtherRadio +>OtherRadio : Symbol(OtherRadio, Decl(reactSFCAndFunctionResolvable.tsx, 5, 13)) + + : Checkbox; +>Checkbox : Symbol(Checkbox, Decl(reactSFCAndFunctionResolvable.tsx, 6, 13)) + + return condition1 ? : ; +>condition1 : Symbol(condition1, Decl(reactSFCAndFunctionResolvable.tsx, 8, 13)) +>Component : Symbol(Component, Decl(reactSFCAndFunctionResolvable.tsx, 13, 7)) +>OtherComponent : Symbol(OtherComponent, Decl(reactSFCAndFunctionResolvable.tsx, 18, 7)) + +}; + diff --git a/tests/baselines/reference/reactSFCAndFunctionResolvable.types b/tests/baselines/reference/reactSFCAndFunctionResolvable.types new file mode 100644 index 00000000000..d8061605b1f --- /dev/null +++ b/tests/baselines/reference/reactSFCAndFunctionResolvable.types @@ -0,0 +1,69 @@ +=== tests/cases/compiler/reactSFCAndFunctionResolvable.tsx === +/// + +import * as React from 'react'; +>React : typeof React + +declare const Radio: (props: {}) => React.ReactElement<{}>; +>Radio : (props: {}) => React.ReactElement<{}> +>props : {} +>React : any + +declare const OtherRadio: () => React.ReactElement<{}>; +>OtherRadio : () => React.ReactElement<{}> +>React : any + +declare const Checkbox: React.SFC; +>Checkbox : React.StatelessComponent<{}> +>React : any + +declare const condition1: boolean; +>condition1 : boolean + +declare const condition2: boolean; +>condition2 : boolean + +declare const condition3: boolean; +>condition3 : boolean + +const RandomComponent: React.SFC = () => { +>RandomComponent : React.StatelessComponent<{}> +>React : any +>() => { const Component = condition1 ? Radio : Checkbox; const OtherComponent = condition2 ? OtherRadio : Checkbox; return condition1 ? : ;} : () => JSX.Element + + const Component = +>Component : React.StatelessComponent<{}> | ((props: {}) => React.ReactElement<{}>) + + condition1 +>condition1 ? Radio : Checkbox : React.StatelessComponent<{}> | ((props: {}) => React.ReactElement<{}>) +>condition1 : boolean + + ? Radio +>Radio : (props: {}) => React.ReactElement<{}> + + : Checkbox; +>Checkbox : React.StatelessComponent<{}> + + const OtherComponent = +>OtherComponent : React.StatelessComponent<{}> | (() => React.ReactElement<{}>) + + condition2 +>condition2 ? OtherRadio : Checkbox : React.StatelessComponent<{}> | (() => React.ReactElement<{}>) +>condition2 : boolean + + ? OtherRadio +>OtherRadio : () => React.ReactElement<{}> + + : Checkbox; +>Checkbox : React.StatelessComponent<{}> + + return condition1 ? : ; +>condition1 ? : : JSX.Element +>condition1 : boolean +> : JSX.Element +>Component : React.StatelessComponent<{}> | ((props: {}) => React.ReactElement<{}>) +> : JSX.Element +>OtherComponent : React.StatelessComponent<{}> | (() => React.ReactElement<{}>) + +}; + diff --git a/tests/baselines/reference/unionTypeCallSignatures.errors.txt b/tests/baselines/reference/unionTypeCallSignatures.errors.txt index 3f0ac662013..5a67bde722c 100644 --- a/tests/baselines/reference/unionTypeCallSignatures.errors.txt +++ b/tests/baselines/reference/unionTypeCallSignatures.errors.txt @@ -7,31 +7,27 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(20,1): error TS23 tests/cases/conformance/types/union/unionTypeCallSignatures.ts(21,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((a: number) => number) | ((a: string) => Date)' has no compatible call signatures. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(24,1): error TS2554: Expected 1 arguments, but got 0. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(26,36): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(29,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((a: string) => string) | ((a: string, b: number) => number)' has no compatible call signatures. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(30,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((a: string) => string) | ((a: string, b: number) => number)' has no compatible call signatures. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(31,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((a: string) => string) | ((a: string, b: number) => number)' has no compatible call signatures. +tests/cases/conformance/types/union/unionTypeCallSignatures.ts(29,1): error TS2554: Expected 2 arguments, but got 0. +tests/cases/conformance/types/union/unionTypeCallSignatures.ts(30,1): error TS2554: Expected 2 arguments, but got 1. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(36,49): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(37,12): error TS2554: Expected 1-2 arguments, but got 0. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(40,12): error TS2554: Expected 2 arguments, but got 1. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(42,49): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(43,12): error TS2554: Expected 2 arguments, but got 0. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(47,12): error TS2554: Expected 1 arguments, but got 2. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(48,12): error TS2554: Expected 1 arguments, but got 2. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(49,12): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/types/union/unionTypeCallSignatures.ts(48,49): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. +tests/cases/conformance/types/union/unionTypeCallSignatures.ts(49,12): error TS2554: Expected 1-2 arguments, but got 0. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(55,45): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(56,12): error TS2555: Expected at least 1 arguments, but got 0. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(59,12): error TS2554: Expected 2 arguments, but got 1. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(61,12): error TS2554: Expected 2 arguments, but got 3. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(62,45): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(63,12): error TS2554: Expected 2 arguments, but got 0. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(67,12): error TS2554: Expected 1 arguments, but got 2. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(68,12): error TS2554: Expected 1 arguments, but got 3. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(69,12): error TS2554: Expected 1 arguments, but got 2. -tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/types/union/unionTypeCallSignatures.ts(69,45): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. +tests/cases/conformance/types/union/unionTypeCallSignatures.ts(70,12): error TS2555: Expected at least 1 arguments, but got 0. tests/cases/conformance/types/union/unionTypeCallSignatures.ts(73,12): error TS2554: Expected 2 arguments, but got 1. -==== tests/cases/conformance/types/union/unionTypeCallSignatures.ts (31 errors) ==== +==== tests/cases/conformance/types/union/unionTypeCallSignatures.ts (27 errors) ==== var numOrDate: number | Date; var strOrBoolean: string | boolean; var strOrNum: string | number; @@ -80,15 +76,15 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(73,12): error TS2 !!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ; - unionWithDifferentParameterCount();// no call signature + unionWithDifferentParameterCount();// needs more args ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((a: string) => string) | ((a: string, b: number) => number)' has no compatible call signatures. - unionWithDifferentParameterCount("hello");// no call signature +!!! error TS2554: Expected 2 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/types/union/unionTypeCallSignatures.ts:28:69: An argument for 'a' was not provided. + unionWithDifferentParameterCount("hello");// needs more args ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((a: string) => string) | ((a: string, b: number) => number)' has no compatible call signatures. - unionWithDifferentParameterCount("hello", 10);// no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((a: string) => string) | ((a: string, b: number) => number)' has no compatible call signatures. +!!! error TS2554: Expected 2 arguments, but got 1. +!!! related TS6210 tests/cases/conformance/types/union/unionTypeCallSignatures.ts:28:80: An argument for 'b' was not provided. + unionWithDifferentParameterCount("hello", 10);// OK var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; }; strOrNum = unionWithOptionalParameter1('hello'); @@ -117,16 +113,14 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(73,12): error TS2 var unionWithOptionalParameter3: { (a: string, b?: number): string; } | { (a: string): number; }; strOrNum = unionWithOptionalParameter3('hello'); - strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 2. - strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 2. - strOrNum = unionWithOptionalParameter3(); // error no call signature + strOrNum = unionWithOptionalParameter3('hello', 10); // ok + strOrNum = unionWithOptionalParameter3('hello', "hello"); // wrong argument type + ~~~~~~~ +!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. + strOrNum = unionWithOptionalParameter3(); // needs more args ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 tests/cases/conformance/types/union/unionTypeCallSignatures.ts:45:76: An argument for 'a' was not provided. +!!! error TS2554: Expected 1-2 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/types/union/unionTypeCallSignatures.ts:45:37: An argument for 'a' was not provided. var unionWithRestParameter1: { (a: string, ...b: number[]): string; } | { (a: string, ...b: number[]): number }; strOrNum = unionWithRestParameter1('hello'); @@ -160,18 +154,14 @@ tests/cases/conformance/types/union/unionTypeCallSignatures.ts(73,12): error TS2 var unionWithRestParameter3: { (a: string, ...b: number[]): string; } | { (a: string): number }; strOrNum = unionWithRestParameter3('hello'); strOrNum = unionWithRestParameter3('hello', 10); // error no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 2. strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 3. - strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 2. + strOrNum = unionWithRestParameter3('hello', "hello"); // wrong argument type + ~~~~~~~ +!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. strOrNum = unionWithRestParameter3(); // error no call signature ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 tests/cases/conformance/types/union/unionTypeCallSignatures.ts:65:76: An argument for 'a' was not provided. +!!! error TS2555: Expected at least 1 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/types/union/unionTypeCallSignatures.ts:65:33: An argument for 'a' was not provided. var unionWithRestParameter4: { (...a: string[]): string; } | { (a: string, b: string): number; }; strOrNum = unionWithRestParameter4("hello"); // error supplied parameters do not match any call signature diff --git a/tests/baselines/reference/unionTypeCallSignatures.js b/tests/baselines/reference/unionTypeCallSignatures.js index 103d92fbef3..4689fd21d1a 100644 --- a/tests/baselines/reference/unionTypeCallSignatures.js +++ b/tests/baselines/reference/unionTypeCallSignatures.js @@ -27,9 +27,9 @@ unionOfDifferentNumberOfSignatures(10); // error - no call signatures unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ; -unionWithDifferentParameterCount();// no call signature -unionWithDifferentParameterCount("hello");// no call signature -unionWithDifferentParameterCount("hello", 10);// no call signature +unionWithDifferentParameterCount();// needs more args +unionWithDifferentParameterCount("hello");// needs more args +unionWithDifferentParameterCount("hello", 10);// OK var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; }; strOrNum = unionWithOptionalParameter1('hello'); @@ -45,9 +45,9 @@ strOrNum = unionWithOptionalParameter2(); // error no call signature var unionWithOptionalParameter3: { (a: string, b?: number): string; } | { (a: string): number; }; strOrNum = unionWithOptionalParameter3('hello'); -strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature -strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature -strOrNum = unionWithOptionalParameter3(); // error no call signature +strOrNum = unionWithOptionalParameter3('hello', 10); // ok +strOrNum = unionWithOptionalParameter3('hello', "hello"); // wrong argument type +strOrNum = unionWithOptionalParameter3(); // needs more args var unionWithRestParameter1: { (a: string, ...b: number[]): string; } | { (a: string, ...b: number[]): number }; strOrNum = unionWithRestParameter1('hello'); @@ -67,7 +67,7 @@ var unionWithRestParameter3: { (a: string, ...b: number[]): string; } | { (a: st strOrNum = unionWithRestParameter3('hello'); strOrNum = unionWithRestParameter3('hello', 10); // error no call signature strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature -strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature +strOrNum = unionWithRestParameter3('hello', "hello"); // wrong argument type strOrNum = unionWithRestParameter3(); // error no call signature var unionWithRestParameter4: { (...a: string[]): string; } | { (a: string, b: string): number; }; @@ -99,9 +99,9 @@ unionOfDifferentNumberOfSignatures(); // error - no call signatures unionOfDifferentNumberOfSignatures(10); // error - no call signatures unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures var unionWithDifferentParameterCount; -unionWithDifferentParameterCount(); // no call signature -unionWithDifferentParameterCount("hello"); // no call signature -unionWithDifferentParameterCount("hello", 10); // no call signature +unionWithDifferentParameterCount(); // needs more args +unionWithDifferentParameterCount("hello"); // needs more args +unionWithDifferentParameterCount("hello", 10); // OK var unionWithOptionalParameter1; strOrNum = unionWithOptionalParameter1('hello'); strOrNum = unionWithOptionalParameter1('hello', 10); @@ -114,9 +114,9 @@ strOrNum = unionWithOptionalParameter2('hello', "hello"); // error no call signa strOrNum = unionWithOptionalParameter2(); // error no call signature var unionWithOptionalParameter3; strOrNum = unionWithOptionalParameter3('hello'); -strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature -strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature -strOrNum = unionWithOptionalParameter3(); // error no call signature +strOrNum = unionWithOptionalParameter3('hello', 10); // ok +strOrNum = unionWithOptionalParameter3('hello', "hello"); // wrong argument type +strOrNum = unionWithOptionalParameter3(); // needs more args var unionWithRestParameter1; strOrNum = unionWithRestParameter1('hello'); strOrNum = unionWithRestParameter1('hello', 10); @@ -133,7 +133,7 @@ var unionWithRestParameter3; strOrNum = unionWithRestParameter3('hello'); strOrNum = unionWithRestParameter3('hello', 10); // error no call signature strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature -strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature +strOrNum = unionWithRestParameter3('hello', "hello"); // wrong argument type strOrNum = unionWithRestParameter3(); // error no call signature var unionWithRestParameter4; strOrNum = unionWithRestParameter4("hello"); // error supplied parameters do not match any call signature diff --git a/tests/baselines/reference/unionTypeCallSignatures.symbols b/tests/baselines/reference/unionTypeCallSignatures.symbols index ed54cb56183..e3f18cb8299 100644 --- a/tests/baselines/reference/unionTypeCallSignatures.symbols +++ b/tests/baselines/reference/unionTypeCallSignatures.symbols @@ -87,13 +87,13 @@ var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b >a : Symbol(a, Decl(unionTypeCallSignatures.ts, 27, 68)) >b : Symbol(b, Decl(unionTypeCallSignatures.ts, 27, 78)) -unionWithDifferentParameterCount();// no call signature +unionWithDifferentParameterCount();// needs more args >unionWithDifferentParameterCount : Symbol(unionWithDifferentParameterCount, Decl(unionTypeCallSignatures.ts, 27, 3)) -unionWithDifferentParameterCount("hello");// no call signature +unionWithDifferentParameterCount("hello");// needs more args >unionWithDifferentParameterCount : Symbol(unionWithDifferentParameterCount, Decl(unionTypeCallSignatures.ts, 27, 3)) -unionWithDifferentParameterCount("hello", 10);// no call signature +unionWithDifferentParameterCount("hello", 10);// OK >unionWithDifferentParameterCount : Symbol(unionWithDifferentParameterCount, Decl(unionTypeCallSignatures.ts, 27, 3)) var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; }; @@ -152,15 +152,15 @@ strOrNum = unionWithOptionalParameter3('hello'); >strOrNum : Symbol(strOrNum, Decl(unionTypeCallSignatures.ts, 2, 3)) >unionWithOptionalParameter3 : Symbol(unionWithOptionalParameter3, Decl(unionTypeCallSignatures.ts, 44, 3)) -strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature +strOrNum = unionWithOptionalParameter3('hello', 10); // ok >strOrNum : Symbol(strOrNum, Decl(unionTypeCallSignatures.ts, 2, 3)) >unionWithOptionalParameter3 : Symbol(unionWithOptionalParameter3, Decl(unionTypeCallSignatures.ts, 44, 3)) -strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature +strOrNum = unionWithOptionalParameter3('hello', "hello"); // wrong argument type >strOrNum : Symbol(strOrNum, Decl(unionTypeCallSignatures.ts, 2, 3)) >unionWithOptionalParameter3 : Symbol(unionWithOptionalParameter3, Decl(unionTypeCallSignatures.ts, 44, 3)) -strOrNum = unionWithOptionalParameter3(); // error no call signature +strOrNum = unionWithOptionalParameter3(); // needs more args >strOrNum : Symbol(strOrNum, Decl(unionTypeCallSignatures.ts, 2, 3)) >unionWithOptionalParameter3 : Symbol(unionWithOptionalParameter3, Decl(unionTypeCallSignatures.ts, 44, 3)) @@ -236,7 +236,7 @@ strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature >strOrNum : Symbol(strOrNum, Decl(unionTypeCallSignatures.ts, 2, 3)) >unionWithRestParameter3 : Symbol(unionWithRestParameter3, Decl(unionTypeCallSignatures.ts, 64, 3)) -strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature +strOrNum = unionWithRestParameter3('hello', "hello"); // wrong argument type >strOrNum : Symbol(strOrNum, Decl(unionTypeCallSignatures.ts, 2, 3)) >unionWithRestParameter3 : Symbol(unionWithRestParameter3, Decl(unionTypeCallSignatures.ts, 64, 3)) diff --git a/tests/baselines/reference/unionTypeCallSignatures.types b/tests/baselines/reference/unionTypeCallSignatures.types index e08d815478e..ef38b524afd 100644 --- a/tests/baselines/reference/unionTypeCallSignatures.types +++ b/tests/baselines/reference/unionTypeCallSignatures.types @@ -109,17 +109,17 @@ var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b >a : string >b : number -unionWithDifferentParameterCount();// no call signature +unionWithDifferentParameterCount();// needs more args >unionWithDifferentParameterCount() : any >unionWithDifferentParameterCount : ((a: string) => string) | ((a: string, b: number) => number) -unionWithDifferentParameterCount("hello");// no call signature +unionWithDifferentParameterCount("hello");// needs more args >unionWithDifferentParameterCount("hello") : any >unionWithDifferentParameterCount : ((a: string) => string) | ((a: string, b: number) => number) >"hello" : "hello" -unionWithDifferentParameterCount("hello", 10);// no call signature ->unionWithDifferentParameterCount("hello", 10) : any +unionWithDifferentParameterCount("hello", 10);// OK +>unionWithDifferentParameterCount("hello", 10) : string | number >unionWithDifferentParameterCount : ((a: string) => string) | ((a: string, b: number) => number) >"hello" : "hello" >10 : 10 @@ -209,15 +209,15 @@ strOrNum = unionWithOptionalParameter3('hello'); >unionWithOptionalParameter3 : ((a: string, b?: number) => string) | ((a: string) => number) >'hello' : "hello" -strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature ->strOrNum = unionWithOptionalParameter3('hello', 10) : any +strOrNum = unionWithOptionalParameter3('hello', 10); // ok +>strOrNum = unionWithOptionalParameter3('hello', 10) : string | number >strOrNum : string | number ->unionWithOptionalParameter3('hello', 10) : any +>unionWithOptionalParameter3('hello', 10) : string | number >unionWithOptionalParameter3 : ((a: string, b?: number) => string) | ((a: string) => number) >'hello' : "hello" >10 : 10 -strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature +strOrNum = unionWithOptionalParameter3('hello', "hello"); // wrong argument type >strOrNum = unionWithOptionalParameter3('hello', "hello") : any >strOrNum : string | number >unionWithOptionalParameter3('hello', "hello") : any @@ -225,7 +225,7 @@ strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signa >'hello' : "hello" >"hello" : "hello" -strOrNum = unionWithOptionalParameter3(); // error no call signature +strOrNum = unionWithOptionalParameter3(); // needs more args >strOrNum = unionWithOptionalParameter3() : any >strOrNum : string | number >unionWithOptionalParameter3() : any @@ -335,23 +335,23 @@ strOrNum = unionWithRestParameter3('hello'); >'hello' : "hello" strOrNum = unionWithRestParameter3('hello', 10); // error no call signature ->strOrNum = unionWithRestParameter3('hello', 10) : any +>strOrNum = unionWithRestParameter3('hello', 10) : string | number >strOrNum : string | number ->unionWithRestParameter3('hello', 10) : any +>unionWithRestParameter3('hello', 10) : string | number >unionWithRestParameter3 : ((a: string, ...b: number[]) => string) | ((a: string) => number) >'hello' : "hello" >10 : 10 strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature ->strOrNum = unionWithRestParameter3('hello', 10, 11) : any +>strOrNum = unionWithRestParameter3('hello', 10, 11) : string | number >strOrNum : string | number ->unionWithRestParameter3('hello', 10, 11) : any +>unionWithRestParameter3('hello', 10, 11) : string | number >unionWithRestParameter3 : ((a: string, ...b: number[]) => string) | ((a: string) => number) >'hello' : "hello" >10 : 10 >11 : 11 -strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature +strOrNum = unionWithRestParameter3('hello', "hello"); // wrong argument type >strOrNum = unionWithRestParameter3('hello', "hello") : any >strOrNum : string | number >unionWithRestParameter3('hello', "hello") : any diff --git a/tests/baselines/reference/unionTypeCallSignatures4.errors.txt b/tests/baselines/reference/unionTypeCallSignatures4.errors.txt index 9d2ca23bbbd..6ba8b9e3015 100644 --- a/tests/baselines/reference/unionTypeCallSignatures4.errors.txt +++ b/tests/baselines/reference/unionTypeCallSignatures4.errors.txt @@ -1,10 +1,8 @@ -tests/cases/conformance/types/union/unionTypeCallSignatures4.ts(10,1): error TS2554: Expected 1-2 arguments, but got 3. -tests/cases/conformance/types/union/unionTypeCallSignatures4.ts(20,1): error TS2554: Expected 1-2 arguments, but got 3. tests/cases/conformance/types/union/unionTypeCallSignatures4.ts(23,1): error TS2554: Expected 2 arguments, but got 1. tests/cases/conformance/types/union/unionTypeCallSignatures4.ts(25,1): error TS2554: Expected 2 arguments, but got 3. -==== tests/cases/conformance/types/union/unionTypeCallSignatures4.ts (4 errors) ==== +==== tests/cases/conformance/types/union/unionTypeCallSignatures4.ts (2 errors) ==== type F1 = (a: string, b?: string) => void; type F2 = (a: string, b?: string, c?: string) => void; type F3 = (a: string, ...rest: string[]) => void; @@ -14,9 +12,7 @@ tests/cases/conformance/types/union/unionTypeCallSignatures4.ts(25,1): error TS2 var f12: F1 | F2; f12("a"); f12("a", "b"); - f12("a", "b", "c"); // error - ~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1-2 arguments, but got 3. + f12("a", "b", "c"); // ok var f34: F3 | F4; f34("a"); @@ -26,9 +22,7 @@ tests/cases/conformance/types/union/unionTypeCallSignatures4.ts(25,1): error TS2 var f1234: F1 | F2 | F3 | F4; f1234("a"); f1234("a", "b"); - f1234("a", "b", "c"); // error - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1-2 arguments, but got 3. + f1234("a", "b", "c"); // ok var f12345: F1 | F2 | F3 | F4 | F5; f12345("a"); // error diff --git a/tests/baselines/reference/unionTypeCallSignatures4.js b/tests/baselines/reference/unionTypeCallSignatures4.js index be9a45b33c9..a98dbb084c6 100644 --- a/tests/baselines/reference/unionTypeCallSignatures4.js +++ b/tests/baselines/reference/unionTypeCallSignatures4.js @@ -8,7 +8,7 @@ type F5 = (a: string, b: string) => void; var f12: F1 | F2; f12("a"); f12("a", "b"); -f12("a", "b", "c"); // error +f12("a", "b", "c"); // ok var f34: F3 | F4; f34("a"); @@ -18,7 +18,7 @@ f34("a", "b", "c"); var f1234: F1 | F2 | F3 | F4; f1234("a"); f1234("a", "b"); -f1234("a", "b", "c"); // error +f1234("a", "b", "c"); // ok var f12345: F1 | F2 | F3 | F4 | F5; f12345("a"); // error @@ -30,7 +30,7 @@ f12345("a", "b", "c"); // error var f12; f12("a"); f12("a", "b"); -f12("a", "b", "c"); // error +f12("a", "b", "c"); // ok var f34; f34("a"); f34("a", "b"); @@ -38,7 +38,7 @@ f34("a", "b", "c"); var f1234; f1234("a"); f1234("a", "b"); -f1234("a", "b", "c"); // error +f1234("a", "b", "c"); // ok var f12345; f12345("a"); // error f12345("a", "b"); diff --git a/tests/baselines/reference/unionTypeCallSignatures4.symbols b/tests/baselines/reference/unionTypeCallSignatures4.symbols index 1157cc99e06..ef3dc1ba9b8 100644 --- a/tests/baselines/reference/unionTypeCallSignatures4.symbols +++ b/tests/baselines/reference/unionTypeCallSignatures4.symbols @@ -37,7 +37,7 @@ f12("a"); f12("a", "b"); >f12 : Symbol(f12, Decl(unionTypeCallSignatures4.ts, 6, 3)) -f12("a", "b", "c"); // error +f12("a", "b", "c"); // ok >f12 : Symbol(f12, Decl(unionTypeCallSignatures4.ts, 6, 3)) var f34: F3 | F4; @@ -67,7 +67,7 @@ f1234("a"); f1234("a", "b"); >f1234 : Symbol(f1234, Decl(unionTypeCallSignatures4.ts, 16, 3)) -f1234("a", "b", "c"); // error +f1234("a", "b", "c"); // ok >f1234 : Symbol(f1234, Decl(unionTypeCallSignatures4.ts, 16, 3)) var f12345: F1 | F2 | F3 | F4 | F5; diff --git a/tests/baselines/reference/unionTypeCallSignatures4.types b/tests/baselines/reference/unionTypeCallSignatures4.types index 12deb1fba37..a02ef1e8bfa 100644 --- a/tests/baselines/reference/unionTypeCallSignatures4.types +++ b/tests/baselines/reference/unionTypeCallSignatures4.types @@ -40,8 +40,8 @@ f12("a", "b"); >"a" : "a" >"b" : "b" -f12("a", "b", "c"); // error ->f12("a", "b", "c") : any +f12("a", "b", "c"); // ok +>f12("a", "b", "c") : void >f12 : F1 | F2 >"a" : "a" >"b" : "b" @@ -82,8 +82,8 @@ f1234("a", "b"); >"a" : "a" >"b" : "b" -f1234("a", "b", "c"); // error ->f1234("a", "b", "c") : any +f1234("a", "b", "c"); // ok +>f1234("a", "b", "c") : void >f1234 : F1 | F2 | F3 | F4 >"a" : "a" >"b" : "b" diff --git a/tests/baselines/reference/unionTypeConstructSignatures.errors.txt b/tests/baselines/reference/unionTypeConstructSignatures.errors.txt index 67973c3c206..a5ad21ba580 100644 --- a/tests/baselines/reference/unionTypeConstructSignatures.errors.txt +++ b/tests/baselines/reference/unionTypeConstructSignatures.errors.txt @@ -7,30 +7,26 @@ tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(20,1): error tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(21,1): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(24,1): error TS2554: Expected 1 arguments, but got 0. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(26,40): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(29,1): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(30,1): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(31,1): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(29,1): error TS2554: Expected 2 arguments, but got 0. +tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(30,1): error TS2554: Expected 2 arguments, but got 1. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(36,53): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(37,12): error TS2554: Expected 1-2 arguments, but got 0. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(40,12): error TS2554: Expected 2 arguments, but got 1. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(42,53): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(43,12): error TS2554: Expected 2 arguments, but got 0. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(47,12): error TS2554: Expected 1 arguments, but got 2. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(48,12): error TS2554: Expected 1 arguments, but got 2. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(49,12): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(48,53): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. +tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(49,12): error TS2554: Expected 1-2 arguments, but got 0. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(55,49): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(56,12): error TS2555: Expected at least 1 arguments, but got 0. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(59,12): error TS2554: Expected 2 arguments, but got 1. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(61,12): error TS2554: Expected 2 arguments, but got 3. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(62,49): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(63,12): error TS2554: Expected 2 arguments, but got 0. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(67,12): error TS2554: Expected 1 arguments, but got 2. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(68,12): error TS2554: Expected 1 arguments, but got 3. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(69,12): error TS2554: Expected 1 arguments, but got 2. -tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(70,12): error TS2554: Expected 1 arguments, but got 0. +tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(69,49): error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. +tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(70,12): error TS2555: Expected at least 1 arguments, but got 0. -==== tests/cases/conformance/types/union/unionTypeConstructSignatures.ts (30 errors) ==== +==== tests/cases/conformance/types/union/unionTypeConstructSignatures.ts (26 errors) ==== var numOrDate: number | Date; var strOrBoolean: string | boolean; var strOrNum: string | number; @@ -79,15 +75,15 @@ tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(70,12): erro !!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. var unionWithDifferentParameterCount: { new (a: string): string; } | { new (a: string, b: number): number; }; - new unionWithDifferentParameterCount();// no call signature + new unionWithDifferentParameterCount();// needs more args ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. - new unionWithDifferentParameterCount("hello");// no call signature +!!! error TS2554: Expected 2 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/types/union/unionTypeConstructSignatures.ts:28:77: An argument for 'a' was not provided. + new unionWithDifferentParameterCount("hello");// needs more args ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. - new unionWithDifferentParameterCount("hello", 10);// no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. +!!! error TS2554: Expected 2 arguments, but got 1. +!!! related TS6210 tests/cases/conformance/types/union/unionTypeConstructSignatures.ts:28:88: An argument for 'b' was not provided. + new unionWithDifferentParameterCount("hello", 10);// ok var unionWithOptionalParameter1: { new (a: string, b?: number): string; } | { new (a: string, b?: number): number; }; strOrNum = new unionWithOptionalParameter1('hello'); @@ -116,16 +112,14 @@ tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(70,12): erro var unionWithOptionalParameter3: { new (a: string, b?: number): string; } | { new (a: string): number; }; strOrNum = new unionWithOptionalParameter3('hello'); // error no call signature - strOrNum = new unionWithOptionalParameter3('hello', 10); // error no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 2. - strOrNum = new unionWithOptionalParameter3('hello', "hello"); // error no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 2. + strOrNum = new unionWithOptionalParameter3('hello', 10); // ok + strOrNum = new unionWithOptionalParameter3('hello', "hello"); // wrong type + ~~~~~~~ +!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. strOrNum = new unionWithOptionalParameter3(); // error no call signature ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 tests/cases/conformance/types/union/unionTypeConstructSignatures.ts:45:84: An argument for 'a' was not provided. +!!! error TS2554: Expected 1-2 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/types/union/unionTypeConstructSignatures.ts:45:41: An argument for 'a' was not provided. var unionWithRestParameter1: { new (a: string, ...b: number[]): string; } | { new (a: string, ...b: number[]): number }; strOrNum = new unionWithRestParameter1('hello'); @@ -158,16 +152,12 @@ tests/cases/conformance/types/union/unionTypeConstructSignatures.ts(70,12): erro var unionWithRestParameter3: { new (a: string, ...b: number[]): string; } | { new (a: string): number }; strOrNum = new unionWithRestParameter3('hello'); // error no call signature - strOrNum = new unionWithRestParameter3('hello', 10); // error no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 2. - strOrNum = new unionWithRestParameter3('hello', 10, 11); // error no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 3. - strOrNum = new unionWithRestParameter3('hello', "hello"); // error no call signature - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 2. + strOrNum = new unionWithRestParameter3('hello', 10); // ok + strOrNum = new unionWithRestParameter3('hello', 10, 11); // ok + strOrNum = new unionWithRestParameter3('hello', "hello"); // wrong type + ~~~~~~~ +!!! error TS2345: Argument of type '"hello"' is not assignable to parameter of type 'number'. strOrNum = new unionWithRestParameter3(); // error no call signature ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2554: Expected 1 arguments, but got 0. -!!! related TS6210 tests/cases/conformance/types/union/unionTypeConstructSignatures.ts:65:84: An argument for 'a' was not provided. \ No newline at end of file +!!! error TS2555: Expected at least 1 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/types/union/unionTypeConstructSignatures.ts:65:37: An argument for 'a' was not provided. \ No newline at end of file diff --git a/tests/baselines/reference/unionTypeConstructSignatures.js b/tests/baselines/reference/unionTypeConstructSignatures.js index 83c3df44603..668ad3f335d 100644 --- a/tests/baselines/reference/unionTypeConstructSignatures.js +++ b/tests/baselines/reference/unionTypeConstructSignatures.js @@ -27,9 +27,9 @@ new unionOfDifferentNumberOfSignatures(10); // error - no call signatures new unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures var unionWithDifferentParameterCount: { new (a: string): string; } | { new (a: string, b: number): number; }; -new unionWithDifferentParameterCount();// no call signature -new unionWithDifferentParameterCount("hello");// no call signature -new unionWithDifferentParameterCount("hello", 10);// no call signature +new unionWithDifferentParameterCount();// needs more args +new unionWithDifferentParameterCount("hello");// needs more args +new unionWithDifferentParameterCount("hello", 10);// ok var unionWithOptionalParameter1: { new (a: string, b?: number): string; } | { new (a: string, b?: number): number; }; strOrNum = new unionWithOptionalParameter1('hello'); @@ -45,8 +45,8 @@ strOrNum = new unionWithOptionalParameter2(); // error no call signature var unionWithOptionalParameter3: { new (a: string, b?: number): string; } | { new (a: string): number; }; strOrNum = new unionWithOptionalParameter3('hello'); // error no call signature -strOrNum = new unionWithOptionalParameter3('hello', 10); // error no call signature -strOrNum = new unionWithOptionalParameter3('hello', "hello"); // error no call signature +strOrNum = new unionWithOptionalParameter3('hello', 10); // ok +strOrNum = new unionWithOptionalParameter3('hello', "hello"); // wrong type strOrNum = new unionWithOptionalParameter3(); // error no call signature var unionWithRestParameter1: { new (a: string, ...b: number[]): string; } | { new (a: string, ...b: number[]): number }; @@ -65,9 +65,9 @@ strOrNum = new unionWithRestParameter2(); // error no call signature var unionWithRestParameter3: { new (a: string, ...b: number[]): string; } | { new (a: string): number }; strOrNum = new unionWithRestParameter3('hello'); // error no call signature -strOrNum = new unionWithRestParameter3('hello', 10); // error no call signature -strOrNum = new unionWithRestParameter3('hello', 10, 11); // error no call signature -strOrNum = new unionWithRestParameter3('hello', "hello"); // error no call signature +strOrNum = new unionWithRestParameter3('hello', 10); // ok +strOrNum = new unionWithRestParameter3('hello', 10, 11); // ok +strOrNum = new unionWithRestParameter3('hello', "hello"); // wrong type strOrNum = new unionWithRestParameter3(); // error no call signature //// [unionTypeConstructSignatures.js] @@ -94,9 +94,9 @@ new unionOfDifferentNumberOfSignatures(); // error - no call signatures new unionOfDifferentNumberOfSignatures(10); // error - no call signatures new unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures var unionWithDifferentParameterCount; -new unionWithDifferentParameterCount(); // no call signature -new unionWithDifferentParameterCount("hello"); // no call signature -new unionWithDifferentParameterCount("hello", 10); // no call signature +new unionWithDifferentParameterCount(); // needs more args +new unionWithDifferentParameterCount("hello"); // needs more args +new unionWithDifferentParameterCount("hello", 10); // ok var unionWithOptionalParameter1; strOrNum = new unionWithOptionalParameter1('hello'); strOrNum = new unionWithOptionalParameter1('hello', 10); @@ -109,8 +109,8 @@ strOrNum = new unionWithOptionalParameter2('hello', "hello"); // error no call s strOrNum = new unionWithOptionalParameter2(); // error no call signature var unionWithOptionalParameter3; strOrNum = new unionWithOptionalParameter3('hello'); // error no call signature -strOrNum = new unionWithOptionalParameter3('hello', 10); // error no call signature -strOrNum = new unionWithOptionalParameter3('hello', "hello"); // error no call signature +strOrNum = new unionWithOptionalParameter3('hello', 10); // ok +strOrNum = new unionWithOptionalParameter3('hello', "hello"); // wrong type strOrNum = new unionWithOptionalParameter3(); // error no call signature var unionWithRestParameter1; strOrNum = new unionWithRestParameter1('hello'); @@ -126,7 +126,7 @@ strOrNum = new unionWithRestParameter2('hello', "hello"); // error no call signa strOrNum = new unionWithRestParameter2(); // error no call signature var unionWithRestParameter3; strOrNum = new unionWithRestParameter3('hello'); // error no call signature -strOrNum = new unionWithRestParameter3('hello', 10); // error no call signature -strOrNum = new unionWithRestParameter3('hello', 10, 11); // error no call signature -strOrNum = new unionWithRestParameter3('hello', "hello"); // error no call signature +strOrNum = new unionWithRestParameter3('hello', 10); // ok +strOrNum = new unionWithRestParameter3('hello', 10, 11); // ok +strOrNum = new unionWithRestParameter3('hello', "hello"); // wrong type strOrNum = new unionWithRestParameter3(); // error no call signature diff --git a/tests/baselines/reference/unionTypeConstructSignatures.symbols b/tests/baselines/reference/unionTypeConstructSignatures.symbols index b4123a6f746..ce4cc97bc1b 100644 --- a/tests/baselines/reference/unionTypeConstructSignatures.symbols +++ b/tests/baselines/reference/unionTypeConstructSignatures.symbols @@ -87,13 +87,13 @@ var unionWithDifferentParameterCount: { new (a: string): string; } | { new (a: s >a : Symbol(a, Decl(unionTypeConstructSignatures.ts, 27, 76)) >b : Symbol(b, Decl(unionTypeConstructSignatures.ts, 27, 86)) -new unionWithDifferentParameterCount();// no call signature +new unionWithDifferentParameterCount();// needs more args >unionWithDifferentParameterCount : Symbol(unionWithDifferentParameterCount, Decl(unionTypeConstructSignatures.ts, 27, 3)) -new unionWithDifferentParameterCount("hello");// no call signature +new unionWithDifferentParameterCount("hello");// needs more args >unionWithDifferentParameterCount : Symbol(unionWithDifferentParameterCount, Decl(unionTypeConstructSignatures.ts, 27, 3)) -new unionWithDifferentParameterCount("hello", 10);// no call signature +new unionWithDifferentParameterCount("hello", 10);// ok >unionWithDifferentParameterCount : Symbol(unionWithDifferentParameterCount, Decl(unionTypeConstructSignatures.ts, 27, 3)) var unionWithOptionalParameter1: { new (a: string, b?: number): string; } | { new (a: string, b?: number): number; }; @@ -152,11 +152,11 @@ strOrNum = new unionWithOptionalParameter3('hello'); // error no call signature >strOrNum : Symbol(strOrNum, Decl(unionTypeConstructSignatures.ts, 2, 3)) >unionWithOptionalParameter3 : Symbol(unionWithOptionalParameter3, Decl(unionTypeConstructSignatures.ts, 44, 3)) -strOrNum = new unionWithOptionalParameter3('hello', 10); // error no call signature +strOrNum = new unionWithOptionalParameter3('hello', 10); // ok >strOrNum : Symbol(strOrNum, Decl(unionTypeConstructSignatures.ts, 2, 3)) >unionWithOptionalParameter3 : Symbol(unionWithOptionalParameter3, Decl(unionTypeConstructSignatures.ts, 44, 3)) -strOrNum = new unionWithOptionalParameter3('hello', "hello"); // error no call signature +strOrNum = new unionWithOptionalParameter3('hello', "hello"); // wrong type >strOrNum : Symbol(strOrNum, Decl(unionTypeConstructSignatures.ts, 2, 3)) >unionWithOptionalParameter3 : Symbol(unionWithOptionalParameter3, Decl(unionTypeConstructSignatures.ts, 44, 3)) @@ -228,15 +228,15 @@ strOrNum = new unionWithRestParameter3('hello'); // error no call signature >strOrNum : Symbol(strOrNum, Decl(unionTypeConstructSignatures.ts, 2, 3)) >unionWithRestParameter3 : Symbol(unionWithRestParameter3, Decl(unionTypeConstructSignatures.ts, 64, 3)) -strOrNum = new unionWithRestParameter3('hello', 10); // error no call signature +strOrNum = new unionWithRestParameter3('hello', 10); // ok >strOrNum : Symbol(strOrNum, Decl(unionTypeConstructSignatures.ts, 2, 3)) >unionWithRestParameter3 : Symbol(unionWithRestParameter3, Decl(unionTypeConstructSignatures.ts, 64, 3)) -strOrNum = new unionWithRestParameter3('hello', 10, 11); // error no call signature +strOrNum = new unionWithRestParameter3('hello', 10, 11); // ok >strOrNum : Symbol(strOrNum, Decl(unionTypeConstructSignatures.ts, 2, 3)) >unionWithRestParameter3 : Symbol(unionWithRestParameter3, Decl(unionTypeConstructSignatures.ts, 64, 3)) -strOrNum = new unionWithRestParameter3('hello', "hello"); // error no call signature +strOrNum = new unionWithRestParameter3('hello', "hello"); // wrong type >strOrNum : Symbol(strOrNum, Decl(unionTypeConstructSignatures.ts, 2, 3)) >unionWithRestParameter3 : Symbol(unionWithRestParameter3, Decl(unionTypeConstructSignatures.ts, 64, 3)) diff --git a/tests/baselines/reference/unionTypeConstructSignatures.types b/tests/baselines/reference/unionTypeConstructSignatures.types index 1a0c077fb56..ca378be3cc3 100644 --- a/tests/baselines/reference/unionTypeConstructSignatures.types +++ b/tests/baselines/reference/unionTypeConstructSignatures.types @@ -109,17 +109,17 @@ var unionWithDifferentParameterCount: { new (a: string): string; } | { new (a: s >a : string >b : number -new unionWithDifferentParameterCount();// no call signature +new unionWithDifferentParameterCount();// needs more args >new unionWithDifferentParameterCount() : any >unionWithDifferentParameterCount : (new (a: string) => string) | (new (a: string, b: number) => number) -new unionWithDifferentParameterCount("hello");// no call signature +new unionWithDifferentParameterCount("hello");// needs more args >new unionWithDifferentParameterCount("hello") : any >unionWithDifferentParameterCount : (new (a: string) => string) | (new (a: string, b: number) => number) >"hello" : "hello" -new unionWithDifferentParameterCount("hello", 10);// no call signature ->new unionWithDifferentParameterCount("hello", 10) : any +new unionWithDifferentParameterCount("hello", 10);// ok +>new unionWithDifferentParameterCount("hello", 10) : string | number >unionWithDifferentParameterCount : (new (a: string) => string) | (new (a: string, b: number) => number) >"hello" : "hello" >10 : 10 @@ -209,15 +209,15 @@ strOrNum = new unionWithOptionalParameter3('hello'); // error no call signature >unionWithOptionalParameter3 : (new (a: string, b?: number) => string) | (new (a: string) => number) >'hello' : "hello" -strOrNum = new unionWithOptionalParameter3('hello', 10); // error no call signature ->strOrNum = new unionWithOptionalParameter3('hello', 10) : any +strOrNum = new unionWithOptionalParameter3('hello', 10); // ok +>strOrNum = new unionWithOptionalParameter3('hello', 10) : string | number >strOrNum : string | number ->new unionWithOptionalParameter3('hello', 10) : any +>new unionWithOptionalParameter3('hello', 10) : string | number >unionWithOptionalParameter3 : (new (a: string, b?: number) => string) | (new (a: string) => number) >'hello' : "hello" >10 : 10 -strOrNum = new unionWithOptionalParameter3('hello', "hello"); // error no call signature +strOrNum = new unionWithOptionalParameter3('hello', "hello"); // wrong type >strOrNum = new unionWithOptionalParameter3('hello', "hello") : any >strOrNum : string | number >new unionWithOptionalParameter3('hello', "hello") : any @@ -334,24 +334,24 @@ strOrNum = new unionWithRestParameter3('hello'); // error no call signature >unionWithRestParameter3 : (new (a: string, ...b: number[]) => string) | (new (a: string) => number) >'hello' : "hello" -strOrNum = new unionWithRestParameter3('hello', 10); // error no call signature ->strOrNum = new unionWithRestParameter3('hello', 10) : any +strOrNum = new unionWithRestParameter3('hello', 10); // ok +>strOrNum = new unionWithRestParameter3('hello', 10) : string | number >strOrNum : string | number ->new unionWithRestParameter3('hello', 10) : any +>new unionWithRestParameter3('hello', 10) : string | number >unionWithRestParameter3 : (new (a: string, ...b: number[]) => string) | (new (a: string) => number) >'hello' : "hello" >10 : 10 -strOrNum = new unionWithRestParameter3('hello', 10, 11); // error no call signature ->strOrNum = new unionWithRestParameter3('hello', 10, 11) : any +strOrNum = new unionWithRestParameter3('hello', 10, 11); // ok +>strOrNum = new unionWithRestParameter3('hello', 10, 11) : string | number >strOrNum : string | number ->new unionWithRestParameter3('hello', 10, 11) : any +>new unionWithRestParameter3('hello', 10, 11) : string | number >unionWithRestParameter3 : (new (a: string, ...b: number[]) => string) | (new (a: string) => number) >'hello' : "hello" >10 : 10 >11 : 11 -strOrNum = new unionWithRestParameter3('hello', "hello"); // error no call signature +strOrNum = new unionWithRestParameter3('hello', "hello"); // wrong type >strOrNum = new unionWithRestParameter3('hello', "hello") : any >strOrNum : string | number >new unionWithRestParameter3('hello', "hello") : any diff --git a/tests/cases/compiler/reactSFCAndFunctionResolvable.tsx b/tests/cases/compiler/reactSFCAndFunctionResolvable.tsx new file mode 100644 index 00000000000..52803da993d --- /dev/null +++ b/tests/cases/compiler/reactSFCAndFunctionResolvable.tsx @@ -0,0 +1,25 @@ +// @jsx: react +/// + +import * as React from 'react'; + +declare const Radio: (props: {}) => React.ReactElement<{}>; +declare const OtherRadio: () => React.ReactElement<{}>; +declare const Checkbox: React.SFC; + +declare const condition1: boolean; +declare const condition2: boolean; +declare const condition3: boolean; + +const RandomComponent: React.SFC = () => { + const Component = + condition1 + ? Radio + : Checkbox; + + const OtherComponent = + condition2 + ? OtherRadio + : Checkbox; + return condition1 ? : ; +}; diff --git a/tests/cases/conformance/types/union/unionTypeCallSignatures.ts b/tests/cases/conformance/types/union/unionTypeCallSignatures.ts index a25d27d9a29..532dd9f3e1f 100644 --- a/tests/cases/conformance/types/union/unionTypeCallSignatures.ts +++ b/tests/cases/conformance/types/union/unionTypeCallSignatures.ts @@ -26,9 +26,9 @@ unionOfDifferentNumberOfSignatures(10); // error - no call signatures unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures var unionWithDifferentParameterCount: { (a: string): string; } | { (a: string, b: number): number; } ; -unionWithDifferentParameterCount();// no call signature -unionWithDifferentParameterCount("hello");// no call signature -unionWithDifferentParameterCount("hello", 10);// no call signature +unionWithDifferentParameterCount();// needs more args +unionWithDifferentParameterCount("hello");// needs more args +unionWithDifferentParameterCount("hello", 10);// OK var unionWithOptionalParameter1: { (a: string, b?: number): string; } | { (a: string, b?: number): number; }; strOrNum = unionWithOptionalParameter1('hello'); @@ -44,9 +44,9 @@ strOrNum = unionWithOptionalParameter2(); // error no call signature var unionWithOptionalParameter3: { (a: string, b?: number): string; } | { (a: string): number; }; strOrNum = unionWithOptionalParameter3('hello'); -strOrNum = unionWithOptionalParameter3('hello', 10); // error no call signature -strOrNum = unionWithOptionalParameter3('hello', "hello"); // error no call signature -strOrNum = unionWithOptionalParameter3(); // error no call signature +strOrNum = unionWithOptionalParameter3('hello', 10); // ok +strOrNum = unionWithOptionalParameter3('hello', "hello"); // wrong argument type +strOrNum = unionWithOptionalParameter3(); // needs more args var unionWithRestParameter1: { (a: string, ...b: number[]): string; } | { (a: string, ...b: number[]): number }; strOrNum = unionWithRestParameter1('hello'); @@ -66,7 +66,7 @@ var unionWithRestParameter3: { (a: string, ...b: number[]): string; } | { (a: st strOrNum = unionWithRestParameter3('hello'); strOrNum = unionWithRestParameter3('hello', 10); // error no call signature strOrNum = unionWithRestParameter3('hello', 10, 11); // error no call signature -strOrNum = unionWithRestParameter3('hello', "hello"); // error no call signature +strOrNum = unionWithRestParameter3('hello', "hello"); // wrong argument type strOrNum = unionWithRestParameter3(); // error no call signature var unionWithRestParameter4: { (...a: string[]): string; } | { (a: string, b: string): number; }; diff --git a/tests/cases/conformance/types/union/unionTypeCallSignatures4.ts b/tests/cases/conformance/types/union/unionTypeCallSignatures4.ts index 1e27acd2083..9ac96262bdc 100644 --- a/tests/cases/conformance/types/union/unionTypeCallSignatures4.ts +++ b/tests/cases/conformance/types/union/unionTypeCallSignatures4.ts @@ -7,7 +7,7 @@ type F5 = (a: string, b: string) => void; var f12: F1 | F2; f12("a"); f12("a", "b"); -f12("a", "b", "c"); // error +f12("a", "b", "c"); // ok var f34: F3 | F4; f34("a"); @@ -17,7 +17,7 @@ f34("a", "b", "c"); var f1234: F1 | F2 | F3 | F4; f1234("a"); f1234("a", "b"); -f1234("a", "b", "c"); // error +f1234("a", "b", "c"); // ok var f12345: F1 | F2 | F3 | F4 | F5; f12345("a"); // error diff --git a/tests/cases/conformance/types/union/unionTypeConstructSignatures.ts b/tests/cases/conformance/types/union/unionTypeConstructSignatures.ts index a02ba610ff7..8f38e38aee0 100644 --- a/tests/cases/conformance/types/union/unionTypeConstructSignatures.ts +++ b/tests/cases/conformance/types/union/unionTypeConstructSignatures.ts @@ -26,9 +26,9 @@ new unionOfDifferentNumberOfSignatures(10); // error - no call signatures new unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures var unionWithDifferentParameterCount: { new (a: string): string; } | { new (a: string, b: number): number; }; -new unionWithDifferentParameterCount();// no call signature -new unionWithDifferentParameterCount("hello");// no call signature -new unionWithDifferentParameterCount("hello", 10);// no call signature +new unionWithDifferentParameterCount();// needs more args +new unionWithDifferentParameterCount("hello");// needs more args +new unionWithDifferentParameterCount("hello", 10);// ok var unionWithOptionalParameter1: { new (a: string, b?: number): string; } | { new (a: string, b?: number): number; }; strOrNum = new unionWithOptionalParameter1('hello'); @@ -44,8 +44,8 @@ strOrNum = new unionWithOptionalParameter2(); // error no call signature var unionWithOptionalParameter3: { new (a: string, b?: number): string; } | { new (a: string): number; }; strOrNum = new unionWithOptionalParameter3('hello'); // error no call signature -strOrNum = new unionWithOptionalParameter3('hello', 10); // error no call signature -strOrNum = new unionWithOptionalParameter3('hello', "hello"); // error no call signature +strOrNum = new unionWithOptionalParameter3('hello', 10); // ok +strOrNum = new unionWithOptionalParameter3('hello', "hello"); // wrong type strOrNum = new unionWithOptionalParameter3(); // error no call signature var unionWithRestParameter1: { new (a: string, ...b: number[]): string; } | { new (a: string, ...b: number[]): number }; @@ -64,7 +64,7 @@ strOrNum = new unionWithRestParameter2(); // error no call signature var unionWithRestParameter3: { new (a: string, ...b: number[]): string; } | { new (a: string): number }; strOrNum = new unionWithRestParameter3('hello'); // error no call signature -strOrNum = new unionWithRestParameter3('hello', 10); // error no call signature -strOrNum = new unionWithRestParameter3('hello', 10, 11); // error no call signature -strOrNum = new unionWithRestParameter3('hello', "hello"); // error no call signature +strOrNum = new unionWithRestParameter3('hello', 10); // ok +strOrNum = new unionWithRestParameter3('hello', 10, 11); // ok +strOrNum = new unionWithRestParameter3('hello', "hello"); // wrong type strOrNum = new unionWithRestParameter3(); // error no call signature \ No newline at end of file diff --git a/tests/cases/fourslash/completionEntryForUnionProperty2.ts b/tests/cases/fourslash/completionEntryForUnionProperty2.ts index c254213e473..1702465aa3e 100644 --- a/tests/cases/fourslash/completionEntryForUnionProperty2.ts +++ b/tests/cases/fourslash/completionEntryForUnionProperty2.ts @@ -17,7 +17,7 @@ verify.completions({ marker: "", exact: [ - { name: "toString", text: "(method) toString(): string", documentation: "Returns a string representation of a string.", }, + { name: "toString", text: "(method) toString(): string (+1 overload)", documentation: "Returns a string representation of a string.", }, { name: "valueOf", text: "(method) valueOf(): string | number", documentation: "Returns the primitive value of the specified object." }, ], });