-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Propagate the error any type in union and intersection construction #58610
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 |
---|---|---|
|
@@ -17052,6 +17052,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
if (flags & TypeFlags.Instantiable) includes |= TypeFlags.IncludesInstantiable; | ||
if (flags & TypeFlags.Intersection && getObjectFlags(type) & ObjectFlags.IsConstrainedTypeVariable) includes |= TypeFlags.IncludesConstrainedTypeVariable; | ||
if (type === wildcardType) includes |= TypeFlags.IncludesWildcard; | ||
if (isErrorType(type)) includes |= TypeFlags.IncludesError; | ||
if (!strictNullChecks && flags & TypeFlags.Nullable) { | ||
if (!(getObjectFlags(type) & ObjectFlags.ContainsWideningType)) includes |= TypeFlags.IncludesNonWideningType; | ||
} | ||
|
@@ -17303,7 +17304,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
if (unionReduction !== UnionReduction.None) { | ||
if (includes & TypeFlags.AnyOrUnknown) { | ||
return includes & TypeFlags.Any ? | ||
includes & TypeFlags.IncludesWildcard ? wildcardType : anyType : | ||
includes & TypeFlags.IncludesWildcard ? wildcardType : | ||
includes & TypeFlags.IncludesError ? errorType : anyType : | ||
unknownType; | ||
} | ||
if (includes & TypeFlags.Undefined) { | ||
|
@@ -17445,6 +17447,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
else { | ||
if (flags & TypeFlags.AnyOrUnknown) { | ||
if (type === wildcardType) includes |= TypeFlags.IncludesWildcard; | ||
if (isErrorType(type)) includes |= TypeFlags.IncludesError; | ||
} | ||
else if (strictNullChecks || !(flags & TypeFlags.Nullable)) { | ||
if (type === missingType) { | ||
|
@@ -17637,7 +17640,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
return neverType; | ||
} | ||
if (includes & TypeFlags.Any) { | ||
return includes & TypeFlags.IncludesWildcard ? wildcardType : anyType; | ||
return includes & TypeFlags.IncludesWildcard ? wildcardType : includes & TypeFlags.IncludesError ? errorType : anyType; | ||
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. it would be nice to have multiple lines here |
||
} | ||
if (!strictNullChecks && includes & TypeFlags.Nullable) { | ||
return includes & TypeFlags.IncludesEmptyObject ? neverType : includes & TypeFlags.Undefined ? undefinedType : nullType; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6185,6 +6185,8 @@ export const enum TypeFlags { | |
StringMapping = 1 << 28, // Uppercase/Lowercase type | ||
/** @internal */ | ||
Reserved1 = 1 << 29, // Used by union/intersection type construction | ||
/** @internal */ | ||
Reserved2 = 1 << 30, // Used by union/intersection type construction | ||
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. remind me, do we have 31 bits available? 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. In modern Node, yep, we do. |
||
|
||
/** @internal */ | ||
AnyOrUnknown = Any | Unknown, | ||
|
@@ -6247,6 +6249,8 @@ export const enum TypeFlags { | |
/** @internal */ | ||
IncludesConstrainedTypeVariable = Reserved1, | ||
/** @internal */ | ||
IncludesError = Reserved2, | ||
/** @internal */ | ||
NotPrimitiveUnion = Any | Unknown | Void | Never | Object | Intersection | IncludesInstantiable, | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//// [declarationSelfReferentialConstraint.ts] //// | ||
export const object = { | ||
foo: <T extends Set<T> | []>(): void => { }, | ||
}; | ||
//// [declarationSelfReferentialConstraint.d.ts] //// | ||
export declare const object: { | ||
foo: <T extends Set<T> | []>() => void; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// @declaration: true | ||
// @emitDeclarationOnly: true | ||
export const object = { | ||
foo: <T extends Set<T> | []>(): void => { }, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These ternaries are officially off the chain now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♀️ I just write the ternaries, I let the formatter figure out how it wants to indent them.