Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter primitives from union when checking for mismatched excess prop…
…s if nonprimitive type is present (#31708) * Filter primitives from union when checking for mismatched excess props if nonprimitive type is present * Use maybeTypeOfKind
- Loading branch information
Showing
6 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/discriminateObjectTypesOnly.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
tests/cases/compiler/discriminateObjectTypesOnly.ts(9,7): error TS2741: Property 'toFixed' is missing in type '{ toString: undefined; }' but required in type '{ toFixed: null; toString: undefined; }'. | ||
|
||
|
||
==== tests/cases/compiler/discriminateObjectTypesOnly.ts (1 errors) ==== | ||
type Thing = number | object; | ||
const k: Thing = { toFixed: null }; // OK, satisfies object | ||
|
||
type Thing2 = number | { toFixed: null } | object; | ||
const q: Thing2 = { toFixed: null }; | ||
const h: Thing2 = { toString: null }; // OK, satisfies object | ||
|
||
type Thing3 = number | { toFixed: null, toString: undefined } | object; | ||
const l: Thing3 = { toString: undefined }; // error, toFixed isn't null | ||
~ | ||
!!! error TS2741: Property 'toFixed' is missing in type '{ toString: undefined; }' but required in type '{ toFixed: null; toString: undefined; }'. | ||
!!! related TS2728 tests/cases/compiler/discriminateObjectTypesOnly.ts:8:26: 'toFixed' is declared here. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//// [discriminateObjectTypesOnly.ts] | ||
type Thing = number | object; | ||
const k: Thing = { toFixed: null }; // OK, satisfies object | ||
|
||
type Thing2 = number | { toFixed: null } | object; | ||
const q: Thing2 = { toFixed: null }; | ||
const h: Thing2 = { toString: null }; // OK, satisfies object | ||
|
||
type Thing3 = number | { toFixed: null, toString: undefined } | object; | ||
const l: Thing3 = { toString: undefined }; // error, toFixed isn't null | ||
|
||
|
||
//// [discriminateObjectTypesOnly.js] | ||
"use strict"; | ||
var k = { toFixed: null }; // OK, satisfies object | ||
var q = { toFixed: null }; | ||
var h = { toString: null }; // OK, satisfies object | ||
var l = { toString: undefined }; // error, toFixed isn't null |
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/discriminateObjectTypesOnly.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
=== tests/cases/compiler/discriminateObjectTypesOnly.ts === | ||
type Thing = number | object; | ||
>Thing : Symbol(Thing, Decl(discriminateObjectTypesOnly.ts, 0, 0)) | ||
|
||
const k: Thing = { toFixed: null }; // OK, satisfies object | ||
>k : Symbol(k, Decl(discriminateObjectTypesOnly.ts, 1, 5)) | ||
>Thing : Symbol(Thing, Decl(discriminateObjectTypesOnly.ts, 0, 0)) | ||
>toFixed : Symbol(toFixed, Decl(discriminateObjectTypesOnly.ts, 1, 18)) | ||
|
||
type Thing2 = number | { toFixed: null } | object; | ||
>Thing2 : Symbol(Thing2, Decl(discriminateObjectTypesOnly.ts, 1, 35)) | ||
>toFixed : Symbol(toFixed, Decl(discriminateObjectTypesOnly.ts, 3, 24)) | ||
|
||
const q: Thing2 = { toFixed: null }; | ||
>q : Symbol(q, Decl(discriminateObjectTypesOnly.ts, 4, 5)) | ||
>Thing2 : Symbol(Thing2, Decl(discriminateObjectTypesOnly.ts, 1, 35)) | ||
>toFixed : Symbol(toFixed, Decl(discriminateObjectTypesOnly.ts, 4, 19)) | ||
|
||
const h: Thing2 = { toString: null }; // OK, satisfies object | ||
>h : Symbol(h, Decl(discriminateObjectTypesOnly.ts, 5, 5)) | ||
>Thing2 : Symbol(Thing2, Decl(discriminateObjectTypesOnly.ts, 1, 35)) | ||
>toString : Symbol(toString, Decl(discriminateObjectTypesOnly.ts, 5, 19)) | ||
|
||
type Thing3 = number | { toFixed: null, toString: undefined } | object; | ||
>Thing3 : Symbol(Thing3, Decl(discriminateObjectTypesOnly.ts, 5, 37)) | ||
>toFixed : Symbol(toFixed, Decl(discriminateObjectTypesOnly.ts, 7, 24)) | ||
>toString : Symbol(toString, Decl(discriminateObjectTypesOnly.ts, 7, 39)) | ||
|
||
const l: Thing3 = { toString: undefined }; // error, toFixed isn't null | ||
>l : Symbol(l, Decl(discriminateObjectTypesOnly.ts, 8, 5)) | ||
>Thing3 : Symbol(Thing3, Decl(discriminateObjectTypesOnly.ts, 5, 37)) | ||
>toString : Symbol(toString, Decl(discriminateObjectTypesOnly.ts, 8, 19)) | ||
>undefined : Symbol(undefined) | ||
|
39 changes: 39 additions & 0 deletions
39
tests/baselines/reference/discriminateObjectTypesOnly.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
=== tests/cases/compiler/discriminateObjectTypesOnly.ts === | ||
type Thing = number | object; | ||
>Thing : Thing | ||
|
||
const k: Thing = { toFixed: null }; // OK, satisfies object | ||
>k : Thing | ||
>{ toFixed: null } : { toFixed: null; } | ||
>toFixed : null | ||
>null : null | ||
|
||
type Thing2 = number | { toFixed: null } | object; | ||
>Thing2 : Thing2 | ||
>toFixed : null | ||
>null : null | ||
|
||
const q: Thing2 = { toFixed: null }; | ||
>q : Thing2 | ||
>{ toFixed: null } : { toFixed: null; } | ||
>toFixed : null | ||
>null : null | ||
|
||
const h: Thing2 = { toString: null }; // OK, satisfies object | ||
>h : Thing2 | ||
>{ toString: null } : { toString: null; } | ||
>toString : null | ||
>null : null | ||
|
||
type Thing3 = number | { toFixed: null, toString: undefined } | object; | ||
>Thing3 : Thing3 | ||
>toFixed : null | ||
>null : null | ||
>toString : undefined | ||
|
||
const l: Thing3 = { toString: undefined }; // error, toFixed isn't null | ||
>l : Thing3 | ||
>{ toString: undefined } : { toString: undefined; } | ||
>toString : undefined | ||
>undefined : undefined | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @strict: true | ||
type Thing = number | object; | ||
const k: Thing = { toFixed: null }; // OK, satisfies object | ||
|
||
type Thing2 = number | { toFixed: null } | object; | ||
const q: Thing2 = { toFixed: null }; | ||
const h: Thing2 = { toString: null }; // OK, satisfies object | ||
|
||
type Thing3 = number | { toFixed: null, toString: undefined } | object; | ||
const l: Thing3 = { toString: undefined }; // error, toFixed isn't null |