From 3d812ef93aece7fd81e0d4ef2b0a961647840ed2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 4 Sep 2018 11:07:50 -0700 Subject: [PATCH 1/6] Added test. --- tests/cases/compiler/errorsWithCallablesInUnions01.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/cases/compiler/errorsWithCallablesInUnions01.ts diff --git a/tests/cases/compiler/errorsWithCallablesInUnions01.ts b/tests/cases/compiler/errorsWithCallablesInUnions01.ts new file mode 100644 index 00000000000..2cb6a3ebd35 --- /dev/null +++ b/tests/cases/compiler/errorsWithCallablesInUnions01.ts @@ -0,0 +1,10 @@ +interface IDirectiveLinkFn { + (scope: TScope): void; +} + +interface IDirectivePrePost { + pre?: IDirectiveLinkFn; + post?: IDirectiveLinkFn; +} + +export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} From 289ae3cca66b79e39a3f60f3bf029462c350fe39 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 4 Sep 2018 15:47:04 -0700 Subject: [PATCH 2/6] Accepted baseleines. --- .../errorsWithCallablesInUnions01.errors.txt | 19 ++++++++++++ .../errorsWithCallablesInUnions01.js | 17 ++++++++++ .../errorsWithCallablesInUnions01.symbols | 31 +++++++++++++++++++ .../errorsWithCallablesInUnions01.types | 19 ++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt create mode 100644 tests/baselines/reference/errorsWithCallablesInUnions01.js create mode 100644 tests/baselines/reference/errorsWithCallablesInUnions01.symbols create mode 100644 tests/baselines/reference/errorsWithCallablesInUnions01.types diff --git a/tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt b/tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt new file mode 100644 index 00000000000..bf117e0c8b3 --- /dev/null +++ b/tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt @@ -0,0 +1,19 @@ +tests/cases/compiler/errorsWithCallablesInUnions01.ts(10,12): error TS2322: Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn | IDirectivePrePost'. + Type '(x: string) => void' has no properties in common with type 'IDirectivePrePost'. + + +==== tests/cases/compiler/errorsWithCallablesInUnions01.ts (1 errors) ==== + interface IDirectiveLinkFn { + (scope: TScope): void; + } + + interface IDirectivePrePost { + pre?: IDirectiveLinkFn; + post?: IDirectiveLinkFn; + } + + export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} + ~~~~ +!!! error TS2322: Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn | IDirectivePrePost'. +!!! error TS2322: Type '(x: string) => void' has no properties in common with type 'IDirectivePrePost'. + \ No newline at end of file diff --git a/tests/baselines/reference/errorsWithCallablesInUnions01.js b/tests/baselines/reference/errorsWithCallablesInUnions01.js new file mode 100644 index 00000000000..f9ea8041b16 --- /dev/null +++ b/tests/baselines/reference/errorsWithCallablesInUnions01.js @@ -0,0 +1,17 @@ +//// [errorsWithCallablesInUnions01.ts] +interface IDirectiveLinkFn { + (scope: TScope): void; +} + +interface IDirectivePrePost { + pre?: IDirectiveLinkFn; + post?: IDirectiveLinkFn; +} + +export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} + + +//// [errorsWithCallablesInUnions01.js] +"use strict"; +exports.__esModule = true; +exports.blah = function (x) { }; diff --git a/tests/baselines/reference/errorsWithCallablesInUnions01.symbols b/tests/baselines/reference/errorsWithCallablesInUnions01.symbols new file mode 100644 index 00000000000..40b48dc2458 --- /dev/null +++ b/tests/baselines/reference/errorsWithCallablesInUnions01.symbols @@ -0,0 +1,31 @@ +=== tests/cases/compiler/errorsWithCallablesInUnions01.ts === +interface IDirectiveLinkFn { +>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithCallablesInUnions01.ts, 0, 0)) +>TScope : Symbol(TScope, Decl(errorsWithCallablesInUnions01.ts, 0, 27)) + + (scope: TScope): void; +>scope : Symbol(scope, Decl(errorsWithCallablesInUnions01.ts, 1, 5)) +>TScope : Symbol(TScope, Decl(errorsWithCallablesInUnions01.ts, 0, 27)) +} + +interface IDirectivePrePost { +>IDirectivePrePost : Symbol(IDirectivePrePost, Decl(errorsWithCallablesInUnions01.ts, 2, 1)) +>TScope : Symbol(TScope, Decl(errorsWithCallablesInUnions01.ts, 4, 28)) + + pre?: IDirectiveLinkFn; +>pre : Symbol(IDirectivePrePost.pre, Decl(errorsWithCallablesInUnions01.ts, 4, 37)) +>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithCallablesInUnions01.ts, 0, 0)) +>TScope : Symbol(TScope, Decl(errorsWithCallablesInUnions01.ts, 4, 28)) + + post?: IDirectiveLinkFn; +>post : Symbol(IDirectivePrePost.post, Decl(errorsWithCallablesInUnions01.ts, 5, 35)) +>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithCallablesInUnions01.ts, 0, 0)) +>TScope : Symbol(TScope, Decl(errorsWithCallablesInUnions01.ts, 4, 28)) +} + +export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} +>blah : Symbol(blah, Decl(errorsWithCallablesInUnions01.ts, 9, 10)) +>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithCallablesInUnions01.ts, 0, 0)) +>IDirectivePrePost : Symbol(IDirectivePrePost, Decl(errorsWithCallablesInUnions01.ts, 2, 1)) +>x : Symbol(x, Decl(errorsWithCallablesInUnions01.ts, 9, 73)) + diff --git a/tests/baselines/reference/errorsWithCallablesInUnions01.types b/tests/baselines/reference/errorsWithCallablesInUnions01.types new file mode 100644 index 00000000000..492d870b6e4 --- /dev/null +++ b/tests/baselines/reference/errorsWithCallablesInUnions01.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/errorsWithCallablesInUnions01.ts === +interface IDirectiveLinkFn { + (scope: TScope): void; +>scope : TScope +} + +interface IDirectivePrePost { + pre?: IDirectiveLinkFn; +>pre : IDirectiveLinkFn + + post?: IDirectiveLinkFn; +>post : IDirectiveLinkFn +} + +export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} +>blah : IDirectiveLinkFn | IDirectivePrePost +>(x: string) => {} : (x: string) => void +>x : string + From c5c594f1e7b2e18b73c3f4fbc7733d1898672511 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 4 Sep 2018 19:25:46 -0700 Subject: [PATCH 3/6] Try finding the first type with a call/construct signature when relating to unions. --- src/compiler/checker.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index da1af15dfa4..7d06f4432f7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11395,7 +11395,8 @@ namespace ts { const bestMatchingType = findMatchingDiscriminantType(source, target) || findMatchingTypeReferenceOrTypeAliasReference(source, target) || - findBestTypeForObjectLiteral(source, target); + findBestTypeForObjectLiteral(source, target) || + findBestTypeForInvokable(source, target); isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true); } @@ -11426,6 +11427,15 @@ namespace ts { } } + function findBestTypeForInvokable(source: Type, unionTarget: UnionOrIntersectionType) { + let signatureKind = SignatureKind.Call; + const hasSignatures = getSignaturesOfType(source, signatureKind).length > 0 || + (signatureKind = SignatureKind.Construct, getSignaturesOfType(source, signatureKind).length > 0); + if (hasSignatures) { + return find(unionTarget.types, t => getSignaturesOfType(t, signatureKind).length > 0); + } + } + // Keep this up-to-date with the same logic within `getApparentTypeOfContextualType`, since they should behave similarly function findMatchingDiscriminantType(source: Type, target: UnionOrIntersectionType) { let match: Type | undefined; From cd399fb49bf25c0c12a9734aedd5babb759829f4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 4 Sep 2018 19:26:00 -0700 Subject: [PATCH 4/6] Accepted baselines. --- ...ntextualTypeWithUnionTypeObjectLiteral.errors.txt | 12 ++++++------ .../errorsWithCallablesInUnions01.errors.txt | 8 ++++++-- .../functionExpressionContextualTyping2.errors.txt | 8 ++++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/baselines/reference/contextualTypeWithUnionTypeObjectLiteral.errors.txt b/tests/baselines/reference/contextualTypeWithUnionTypeObjectLiteral.errors.txt index e4ffa209e6f..fb44cb57da7 100644 --- a/tests/baselines/reference/contextualTypeWithUnionTypeObjectLiteral.errors.txt +++ b/tests/baselines/reference/contextualTypeWithUnionTypeObjectLiteral.errors.txt @@ -22,9 +22,9 @@ tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts( Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(58,5): error TS2322: Type '(a: string, b: number) => string | number' is not assignable to type '((a: string, b: number) => string) | ((a: string, b: number) => number)'. - Type '(a: string, b: number) => string | number' is not assignable to type '(a: string, b: number) => number'. - Type 'string | number' is not assignable to type 'number'. - Type 'string' is not assignable to type 'number'. + Type '(a: string, b: number) => string | number' is not assignable to type '(a: string, b: number) => string'. + Type 'string | number' is not assignable to type 'string'. + Type 'number' is not assignable to type 'string'. ==== tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts (6 errors) ==== @@ -116,8 +116,8 @@ tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts( commonMethodDifferentReturnType: (a, b) => strOrNumber, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2322: Type '(a: string, b: number) => string | number' is not assignable to type '((a: string, b: number) => string) | ((a: string, b: number) => number)'. -!!! error TS2322: Type '(a: string, b: number) => string | number' is not assignable to type '(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'. +!!! error TS2322: Type '(a: string, b: number) => string | number' is not assignable to type '(a: string, b: number) => string'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. !!! related TS6500 tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts:35:5: The expected type comes from property 'commonMethodDifferentReturnType' which is declared here on type 'I11 | I21' }; \ No newline at end of file diff --git a/tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt b/tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt index bf117e0c8b3..4881c4f7ff1 100644 --- a/tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt +++ b/tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt @@ -1,5 +1,7 @@ tests/cases/compiler/errorsWithCallablesInUnions01.ts(10,12): error TS2322: Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn | IDirectivePrePost'. - Type '(x: string) => void' has no properties in common with type 'IDirectivePrePost'. + Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn'. + Types of parameters 'x' and 'scope' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/errorsWithCallablesInUnions01.ts (1 errors) ==== @@ -15,5 +17,7 @@ tests/cases/compiler/errorsWithCallablesInUnions01.ts(10,12): error TS2322: Type export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} ~~~~ !!! error TS2322: Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn | IDirectivePrePost'. -!!! error TS2322: Type '(x: string) => void' has no properties in common with type 'IDirectivePrePost'. +!!! error TS2322: Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn'. +!!! error TS2322: Types of parameters 'x' and 'scope' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt index 6a3a7998f09..d50e0c4b6d6 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt +++ b/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(11,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. - Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. - Type 'boolean' is not assignable to type 'string'. + Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => number'. + Type 'boolean' is not assignable to type 'number'. ==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts (1 errors) ==== @@ -17,5 +17,5 @@ tests/cases/conformance/expressions/contextualTyping/functionExpressionContextua a1 = (foo, bar) => { return true; } // Error ~~ !!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. -!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. -!!! error TS2322: Type 'boolean' is not assignable to type 'string'. \ No newline at end of file +!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => number'. +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. \ No newline at end of file From d989e10c4926e115c92325202430ea1fc75d653f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 5 Sep 2018 11:50:47 -0700 Subject: [PATCH 5/6] Renamed test. --- .../compiler/errorsWithCallablesInUnions01.ts | 10 ---------- .../compiler/errorsWithInvokablesInUnions01.ts | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) delete mode 100644 tests/cases/compiler/errorsWithCallablesInUnions01.ts create mode 100644 tests/cases/compiler/errorsWithInvokablesInUnions01.ts diff --git a/tests/cases/compiler/errorsWithCallablesInUnions01.ts b/tests/cases/compiler/errorsWithCallablesInUnions01.ts deleted file mode 100644 index 2cb6a3ebd35..00000000000 --- a/tests/cases/compiler/errorsWithCallablesInUnions01.ts +++ /dev/null @@ -1,10 +0,0 @@ -interface IDirectiveLinkFn { - (scope: TScope): void; -} - -interface IDirectivePrePost { - pre?: IDirectiveLinkFn; - post?: IDirectiveLinkFn; -} - -export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} diff --git a/tests/cases/compiler/errorsWithInvokablesInUnions01.ts b/tests/cases/compiler/errorsWithInvokablesInUnions01.ts new file mode 100644 index 00000000000..56491af71ce --- /dev/null +++ b/tests/cases/compiler/errorsWithInvokablesInUnions01.ts @@ -0,0 +1,18 @@ +interface ConstructableA { + new(): { somePropA: any }; +} + +interface IDirectiveLinkFn { + (scope: TScope): void; +} + +interface IDirectivePrePost { + pre?: IDirectiveLinkFn; + post?: IDirectiveLinkFn; +} + +export let blah: IDirectiveLinkFn | ConstructableA | IDirectivePrePost = (x: string) => {} + +export let ctor: IDirectiveLinkFn | ConstructableA | IDirectivePrePost = class { + someUnaccountedProp: any; +} From d0673762f10262209401765ea4bfd5810252b63c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 5 Sep 2018 15:12:23 -0700 Subject: [PATCH 6/6] Accepted baselines. --- .../errorsWithCallablesInUnions01.errors.txt | 23 --------- .../errorsWithCallablesInUnions01.js | 17 ------- .../errorsWithCallablesInUnions01.symbols | 31 ------------ .../errorsWithCallablesInUnions01.types | 19 ------- .../errorsWithInvokablesInUnions01.errors.txt | 40 +++++++++++++++ .../errorsWithInvokablesInUnions01.js | 30 ++++++++++++ .../errorsWithInvokablesInUnions01.symbols | 49 +++++++++++++++++++ .../errorsWithInvokablesInUnions01.types | 32 ++++++++++++ 8 files changed, 151 insertions(+), 90 deletions(-) delete mode 100644 tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt delete mode 100644 tests/baselines/reference/errorsWithCallablesInUnions01.js delete mode 100644 tests/baselines/reference/errorsWithCallablesInUnions01.symbols delete mode 100644 tests/baselines/reference/errorsWithCallablesInUnions01.types create mode 100644 tests/baselines/reference/errorsWithInvokablesInUnions01.errors.txt create mode 100644 tests/baselines/reference/errorsWithInvokablesInUnions01.js create mode 100644 tests/baselines/reference/errorsWithInvokablesInUnions01.symbols create mode 100644 tests/baselines/reference/errorsWithInvokablesInUnions01.types diff --git a/tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt b/tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt deleted file mode 100644 index 4881c4f7ff1..00000000000 --- a/tests/baselines/reference/errorsWithCallablesInUnions01.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/compiler/errorsWithCallablesInUnions01.ts(10,12): error TS2322: Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn | IDirectivePrePost'. - Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn'. - Types of parameters 'x' and 'scope' are incompatible. - Type 'number' is not assignable to type 'string'. - - -==== tests/cases/compiler/errorsWithCallablesInUnions01.ts (1 errors) ==== - interface IDirectiveLinkFn { - (scope: TScope): void; - } - - interface IDirectivePrePost { - pre?: IDirectiveLinkFn; - post?: IDirectiveLinkFn; - } - - export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} - ~~~~ -!!! error TS2322: Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn | IDirectivePrePost'. -!!! error TS2322: Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn'. -!!! error TS2322: Types of parameters 'x' and 'scope' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string'. - \ No newline at end of file diff --git a/tests/baselines/reference/errorsWithCallablesInUnions01.js b/tests/baselines/reference/errorsWithCallablesInUnions01.js deleted file mode 100644 index f9ea8041b16..00000000000 --- a/tests/baselines/reference/errorsWithCallablesInUnions01.js +++ /dev/null @@ -1,17 +0,0 @@ -//// [errorsWithCallablesInUnions01.ts] -interface IDirectiveLinkFn { - (scope: TScope): void; -} - -interface IDirectivePrePost { - pre?: IDirectiveLinkFn; - post?: IDirectiveLinkFn; -} - -export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} - - -//// [errorsWithCallablesInUnions01.js] -"use strict"; -exports.__esModule = true; -exports.blah = function (x) { }; diff --git a/tests/baselines/reference/errorsWithCallablesInUnions01.symbols b/tests/baselines/reference/errorsWithCallablesInUnions01.symbols deleted file mode 100644 index 40b48dc2458..00000000000 --- a/tests/baselines/reference/errorsWithCallablesInUnions01.symbols +++ /dev/null @@ -1,31 +0,0 @@ -=== tests/cases/compiler/errorsWithCallablesInUnions01.ts === -interface IDirectiveLinkFn { ->IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithCallablesInUnions01.ts, 0, 0)) ->TScope : Symbol(TScope, Decl(errorsWithCallablesInUnions01.ts, 0, 27)) - - (scope: TScope): void; ->scope : Symbol(scope, Decl(errorsWithCallablesInUnions01.ts, 1, 5)) ->TScope : Symbol(TScope, Decl(errorsWithCallablesInUnions01.ts, 0, 27)) -} - -interface IDirectivePrePost { ->IDirectivePrePost : Symbol(IDirectivePrePost, Decl(errorsWithCallablesInUnions01.ts, 2, 1)) ->TScope : Symbol(TScope, Decl(errorsWithCallablesInUnions01.ts, 4, 28)) - - pre?: IDirectiveLinkFn; ->pre : Symbol(IDirectivePrePost.pre, Decl(errorsWithCallablesInUnions01.ts, 4, 37)) ->IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithCallablesInUnions01.ts, 0, 0)) ->TScope : Symbol(TScope, Decl(errorsWithCallablesInUnions01.ts, 4, 28)) - - post?: IDirectiveLinkFn; ->post : Symbol(IDirectivePrePost.post, Decl(errorsWithCallablesInUnions01.ts, 5, 35)) ->IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithCallablesInUnions01.ts, 0, 0)) ->TScope : Symbol(TScope, Decl(errorsWithCallablesInUnions01.ts, 4, 28)) -} - -export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} ->blah : Symbol(blah, Decl(errorsWithCallablesInUnions01.ts, 9, 10)) ->IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithCallablesInUnions01.ts, 0, 0)) ->IDirectivePrePost : Symbol(IDirectivePrePost, Decl(errorsWithCallablesInUnions01.ts, 2, 1)) ->x : Symbol(x, Decl(errorsWithCallablesInUnions01.ts, 9, 73)) - diff --git a/tests/baselines/reference/errorsWithCallablesInUnions01.types b/tests/baselines/reference/errorsWithCallablesInUnions01.types deleted file mode 100644 index 492d870b6e4..00000000000 --- a/tests/baselines/reference/errorsWithCallablesInUnions01.types +++ /dev/null @@ -1,19 +0,0 @@ -=== tests/cases/compiler/errorsWithCallablesInUnions01.ts === -interface IDirectiveLinkFn { - (scope: TScope): void; ->scope : TScope -} - -interface IDirectivePrePost { - pre?: IDirectiveLinkFn; ->pre : IDirectiveLinkFn - - post?: IDirectiveLinkFn; ->post : IDirectiveLinkFn -} - -export let blah: IDirectiveLinkFn | IDirectivePrePost = (x: string) => {} ->blah : IDirectiveLinkFn | IDirectivePrePost ->(x: string) => {} : (x: string) => void ->x : string - diff --git a/tests/baselines/reference/errorsWithInvokablesInUnions01.errors.txt b/tests/baselines/reference/errorsWithInvokablesInUnions01.errors.txt new file mode 100644 index 00000000000..b70d3d744ef --- /dev/null +++ b/tests/baselines/reference/errorsWithInvokablesInUnions01.errors.txt @@ -0,0 +1,40 @@ +tests/cases/compiler/errorsWithInvokablesInUnions01.ts(14,12): error TS2322: Type '(x: string) => void' is not assignable to type 'ConstructableA | IDirectiveLinkFn | IDirectivePrePost'. + Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn'. + Types of parameters 'x' and 'scope' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/errorsWithInvokablesInUnions01.ts(16,12): error TS2322: Type 'typeof ctor' is not assignable to type 'ConstructableA | IDirectiveLinkFn | IDirectivePrePost'. + Type 'typeof ctor' is not assignable to type 'ConstructableA'. + Type 'ctor' is not assignable to type '{ somePropA: any; }'. + Property 'somePropA' is missing in type 'ctor'. + + +==== tests/cases/compiler/errorsWithInvokablesInUnions01.ts (2 errors) ==== + interface ConstructableA { + new(): { somePropA: any }; + } + + interface IDirectiveLinkFn { + (scope: TScope): void; + } + + interface IDirectivePrePost { + pre?: IDirectiveLinkFn; + post?: IDirectiveLinkFn; + } + + export let blah: IDirectiveLinkFn | ConstructableA | IDirectivePrePost = (x: string) => {} + ~~~~ +!!! error TS2322: Type '(x: string) => void' is not assignable to type 'ConstructableA | IDirectiveLinkFn | IDirectivePrePost'. +!!! error TS2322: Type '(x: string) => void' is not assignable to type 'IDirectiveLinkFn'. +!!! error TS2322: Types of parameters 'x' and 'scope' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + + export let ctor: IDirectiveLinkFn | ConstructableA | IDirectivePrePost = class { + ~~~~ +!!! error TS2322: Type 'typeof ctor' is not assignable to type 'ConstructableA | IDirectiveLinkFn | IDirectivePrePost'. +!!! error TS2322: Type 'typeof ctor' is not assignable to type 'ConstructableA'. +!!! error TS2322: Type 'ctor' is not assignable to type '{ somePropA: any; }'. +!!! error TS2322: Property 'somePropA' is missing in type 'ctor'. + someUnaccountedProp: any; + } + \ No newline at end of file diff --git a/tests/baselines/reference/errorsWithInvokablesInUnions01.js b/tests/baselines/reference/errorsWithInvokablesInUnions01.js new file mode 100644 index 00000000000..47c2df0fc23 --- /dev/null +++ b/tests/baselines/reference/errorsWithInvokablesInUnions01.js @@ -0,0 +1,30 @@ +//// [errorsWithInvokablesInUnions01.ts] +interface ConstructableA { + new(): { somePropA: any }; +} + +interface IDirectiveLinkFn { + (scope: TScope): void; +} + +interface IDirectivePrePost { + pre?: IDirectiveLinkFn; + post?: IDirectiveLinkFn; +} + +export let blah: IDirectiveLinkFn | ConstructableA | IDirectivePrePost = (x: string) => {} + +export let ctor: IDirectiveLinkFn | ConstructableA | IDirectivePrePost = class { + someUnaccountedProp: any; +} + + +//// [errorsWithInvokablesInUnions01.js] +"use strict"; +exports.__esModule = true; +exports.blah = function (x) { }; +exports.ctor = /** @class */ (function () { + function class_1() { + } + return class_1; +}()); diff --git a/tests/baselines/reference/errorsWithInvokablesInUnions01.symbols b/tests/baselines/reference/errorsWithInvokablesInUnions01.symbols new file mode 100644 index 00000000000..a82cecb7665 --- /dev/null +++ b/tests/baselines/reference/errorsWithInvokablesInUnions01.symbols @@ -0,0 +1,49 @@ +=== tests/cases/compiler/errorsWithInvokablesInUnions01.ts === +interface ConstructableA { +>ConstructableA : Symbol(ConstructableA, Decl(errorsWithInvokablesInUnions01.ts, 0, 0)) + + new(): { somePropA: any }; +>somePropA : Symbol(somePropA, Decl(errorsWithInvokablesInUnions01.ts, 1, 10)) +} + +interface IDirectiveLinkFn { +>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithInvokablesInUnions01.ts, 2, 1)) +>TScope : Symbol(TScope, Decl(errorsWithInvokablesInUnions01.ts, 4, 27)) + + (scope: TScope): void; +>scope : Symbol(scope, Decl(errorsWithInvokablesInUnions01.ts, 5, 5)) +>TScope : Symbol(TScope, Decl(errorsWithInvokablesInUnions01.ts, 4, 27)) +} + +interface IDirectivePrePost { +>IDirectivePrePost : Symbol(IDirectivePrePost, Decl(errorsWithInvokablesInUnions01.ts, 6, 1)) +>TScope : Symbol(TScope, Decl(errorsWithInvokablesInUnions01.ts, 8, 28)) + + pre?: IDirectiveLinkFn; +>pre : Symbol(IDirectivePrePost.pre, Decl(errorsWithInvokablesInUnions01.ts, 8, 37)) +>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithInvokablesInUnions01.ts, 2, 1)) +>TScope : Symbol(TScope, Decl(errorsWithInvokablesInUnions01.ts, 8, 28)) + + post?: IDirectiveLinkFn; +>post : Symbol(IDirectivePrePost.post, Decl(errorsWithInvokablesInUnions01.ts, 9, 35)) +>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithInvokablesInUnions01.ts, 2, 1)) +>TScope : Symbol(TScope, Decl(errorsWithInvokablesInUnions01.ts, 8, 28)) +} + +export let blah: IDirectiveLinkFn | ConstructableA | IDirectivePrePost = (x: string) => {} +>blah : Symbol(blah, Decl(errorsWithInvokablesInUnions01.ts, 13, 10)) +>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithInvokablesInUnions01.ts, 2, 1)) +>ConstructableA : Symbol(ConstructableA, Decl(errorsWithInvokablesInUnions01.ts, 0, 0)) +>IDirectivePrePost : Symbol(IDirectivePrePost, Decl(errorsWithInvokablesInUnions01.ts, 6, 1)) +>x : Symbol(x, Decl(errorsWithInvokablesInUnions01.ts, 13, 90)) + +export let ctor: IDirectiveLinkFn | ConstructableA | IDirectivePrePost = class { +>ctor : Symbol(ctor, Decl(errorsWithInvokablesInUnions01.ts, 15, 10)) +>IDirectiveLinkFn : Symbol(IDirectiveLinkFn, Decl(errorsWithInvokablesInUnions01.ts, 2, 1)) +>ConstructableA : Symbol(ConstructableA, Decl(errorsWithInvokablesInUnions01.ts, 0, 0)) +>IDirectivePrePost : Symbol(IDirectivePrePost, Decl(errorsWithInvokablesInUnions01.ts, 6, 1)) + + someUnaccountedProp: any; +>someUnaccountedProp : Symbol(ctor.someUnaccountedProp, Decl(errorsWithInvokablesInUnions01.ts, 15, 96)) +} + diff --git a/tests/baselines/reference/errorsWithInvokablesInUnions01.types b/tests/baselines/reference/errorsWithInvokablesInUnions01.types new file mode 100644 index 00000000000..3497a71cad8 --- /dev/null +++ b/tests/baselines/reference/errorsWithInvokablesInUnions01.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/errorsWithInvokablesInUnions01.ts === +interface ConstructableA { + new(): { somePropA: any }; +>somePropA : any +} + +interface IDirectiveLinkFn { + (scope: TScope): void; +>scope : TScope +} + +interface IDirectivePrePost { + pre?: IDirectiveLinkFn; +>pre : IDirectiveLinkFn + + post?: IDirectiveLinkFn; +>post : IDirectiveLinkFn +} + +export let blah: IDirectiveLinkFn | ConstructableA | IDirectivePrePost = (x: string) => {} +>blah : ConstructableA | IDirectiveLinkFn | IDirectivePrePost +>(x: string) => {} : (x: string) => void +>x : string + +export let ctor: IDirectiveLinkFn | ConstructableA | IDirectivePrePost = class { +>ctor : ConstructableA | IDirectiveLinkFn | IDirectivePrePost +>class { someUnaccountedProp: any;} : typeof ctor + + someUnaccountedProp: any; +>someUnaccountedProp : any +} +