-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Require at least a single match when defining discriminable properties #53654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22627,12 +22627,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
} | ||
let i = 0; | ||
for (const type of target.types) { | ||
const targetType = getTypeOfPropertyOfType(type, propertyName); | ||
if (targetType && related(getDiscriminatingType(), targetType)) { | ||
discriminable[i] = discriminable[i] === undefined ? true : discriminable[i]; | ||
} | ||
else { | ||
discriminable[i] = false; | ||
if (discriminable[i] === undefined) { | ||
const targetType = getTypeOfPropertyOfType(type, propertyName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To explain this change: This line says that "discriminated types stop at 'true'", but the code is overwriting a potentially true |
||
discriminable[i] = !!(targetType && related(getDiscriminatingType(), targetType)); | ||
} | ||
i++; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme | |
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithDiscriminatedUnion.ts(58,5): error TS2322: Type 'S' is not assignable to type 'T'. | ||
Property 'c' is missing in type 'S' but required in type '{ a: 2; b: 4 | 3; c: string; }'. | ||
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithDiscriminatedUnion.ts(82,5): error TS2322: Type 'S' is not assignable to type 'T'. | ||
Type 'S' is not assignable to type '{ a: N; b: N; c: 2; }'. | ||
Types of property 'c' are incompatible. | ||
Type 'N' is not assignable to type '2'. | ||
Type '0' is not assignable to type '2'. | ||
Comment on lines
-9
to
-12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of these errors not being included anymore and I'll try to keep them, but IMO the diagnostic changes in the other files do make sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DanielRosenwasser @ahejlsberg Wait I think that those errors are a bug (?). The example says that |
||
|
||
|
||
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithDiscriminatedUnion.ts (3 errors) ==== | ||
|
@@ -107,10 +103,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme | |
t = s; | ||
~ | ||
!!! error TS2322: Type 'S' is not assignable to type 'T'. | ||
!!! error TS2322: Type 'S' is not assignable to type '{ a: N; b: N; c: 2; }'. | ||
!!! error TS2322: Types of property 'c' are incompatible. | ||
!!! error TS2322: Type 'N' is not assignable to type '2'. | ||
!!! error TS2322: Type '0' is not assignable to type '2'. | ||
} | ||
|
||
// https://github.com/Microsoft/TypeScript/issues/14865 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// type Foo = { a: 0, b: 'x' } | { a: 0, b: 'y' } | { a: 1, b: 'z' }; | ||
//// const foo: Foo = { a: 0, b: '/*1*/' } | ||
//// | ||
//// type Bar = { a: 0, b: 'fx' } | { a: 0, b: 'fy' } | { a: 1, b: 'fz' }; | ||
//// const bar: Bar = { a: 0, b: 'f/*2*/' } | ||
verify.completions({ marker: "1", triggerCharacter: "'", includes: [ "x", "y" ], excludes: [ "z" ] }); | ||
verify.completions({ marker: "2", triggerCharacter: "'", includes: [ "fx", "fy" ], excludes: [ "fz" ] }); |
Uh oh!
There was an error while loading. Please reload this page.