Propagate the error any type in union and intersection construction (#58610)

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
This commit is contained in:
Wesley WighamandTypeScript Bot authored and GitHub committed 2024-05-23 09:38:57 -07:00
1 parent a203ace7af
commit b3f3bb3d38
13 files changed
+42 -22

No files matched your search

+5 -2
View File
@@ -17057,6 +17057,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;
}
@@ -17308,7 +17309,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) {
@@ -17450,6 +17452,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) {
@@ -17642,7 +17645,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;
}
if (!strictNullChecks && includes & TypeFlags.Nullable) {
return includes & TypeFlags.IncludesEmptyObject ? neverType : includes & TypeFlags.Undefined ? undefinedType : nullType;
+4
View File
@@ -6184,6 +6184,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
/** @internal */
AnyOrUnknown = Any | Unknown,
@@ -6246,6 +6248,8 @@ export const enum TypeFlags {
/** @internal */
IncludesConstrainedTypeVariable = Reserved1,
/** @internal */
IncludesError = Reserved2,
/** @internal */
NotPrimitiveUnion = Any | Unknown | Void | Never | Object | Intersection | IncludesInstantiable,
}
@@ -23,7 +23,7 @@ function foo() {
>o : any
return (o == null) ? create(base) : defineProperties(Object(o), descriptors);
>(o == null) ? create(base) : defineProperties(Object(o), descriptors) : any
>(o == null) ? create(base) : defineProperties(Object(o), descriptors) : error
>(o == null) : boolean
> : ^^^^^^^
>o == null : boolean
@@ -15,7 +15,7 @@ const a = (
> : ^^^
{0 ? (
>0 ? ( emptyMessage // must be identifier? ) : ( // must be exactly two expression holes <span> {0}{0} </span> ) : any
>0 ? ( emptyMessage // must be identifier? ) : ( // must be exactly two expression holes <span> {0}{0} </span> ) : error
>0 : 0
> : ^
>( emptyMessage // must be identifier? ) : any
@@ -36,7 +36,7 @@ const oobj = {
}
obj[incr()] ??= incr();
>obj[incr()] ??= incr() : any
>obj[incr()] ??= incr() : error
>obj[incr()] : error
>obj : {}
> : ^^
@@ -50,7 +50,7 @@ obj[incr()] ??= incr();
> : ^^^^^^^^^^^^
oobj["obj"][incr()] ??= incr();
>oobj["obj"][incr()] ??= incr() : any
>oobj["obj"][incr()] ??= incr() : error
>oobj["obj"][incr()] : error
>oobj["obj"] : {}
> : ^^
@@ -36,7 +36,7 @@ const oobj = {
}
obj[incr()] ??= incr();
>obj[incr()] ??= incr() : any
>obj[incr()] ??= incr() : error
>obj[incr()] : error
>obj : {}
> : ^^
@@ -50,7 +50,7 @@ obj[incr()] ??= incr();
> : ^^^^^^^^^^^^
oobj["obj"][incr()] ??= incr();
>oobj["obj"][incr()] ??= incr() : any
>oobj["obj"][incr()] ??= incr() : error
>oobj["obj"][incr()] : error
>oobj["obj"] : {}
> : ^^
@@ -36,7 +36,7 @@ const oobj = {
}
obj[incr()] ??= incr();
>obj[incr()] ??= incr() : any
>obj[incr()] ??= incr() : error
>obj[incr()] : error
>obj : {}
> : ^^
@@ -50,7 +50,7 @@ obj[incr()] ??= incr();
> : ^^^^^^^^^^^^
oobj["obj"][incr()] ??= incr();
>oobj["obj"][incr()] ??= incr() : any
>oobj["obj"][incr()] ??= incr() : error
>oobj["obj"][incr()] : error
>oobj["obj"] : {}
> : ^^
@@ -36,7 +36,7 @@ const oobj = {
}
obj[incr()] ??= incr();
>obj[incr()] ??= incr() : any
>obj[incr()] ??= incr() : error
>obj[incr()] : error
>obj : {}
> : ^^
@@ -50,7 +50,7 @@ obj[incr()] ??= incr();
> : ^^^^^^^^^^^^
oobj["obj"][incr()] ??= incr();
>oobj["obj"][incr()] ??= incr() : any
>oobj["obj"][incr()] ??= incr() : error
>oobj["obj"][incr()] : error
>oobj["obj"] : {}
> : ^^
@@ -101,11 +101,11 @@ function Y(e, t) {
> : ^^^^^^
>v = f, (0 | (f = f + 288 | 0)) >= (0 | l) && b(288), T = v, A = t : any
>v = f, (0 | (f = f + 288 | 0)) >= (0 | l) && b(288), T = v : error
>v = f, (0 | (f = f + 288 | 0)) >= (0 | l) && b(288) : any
>v = f, (0 | (f = f + 288 | 0)) >= (0 | l) && b(288) : error
>v = f : error
>v : any
>f : error
>(0 | (f = f + 288 | 0)) >= (0 | l) && b(288) : any
>(0 | (f = f + 288 | 0)) >= (0 | l) && b(288) : error
>(0 | (f = f + 288 | 0)) >= (0 | l) : boolean
> : ^^^^^^^
>(0 | (f = f + 288 | 0)) : number
@@ -298,11 +298,11 @@ function Y(e, t) {
> : ^^^^^^
>s = f, (0 | (f = f + 32 | 0)) >= (0 | l) && b(32), i = e, a = t : any
>s = f, (0 | (f = f + 32 | 0)) >= (0 | l) && b(32), i = e : error
>s = f, (0 | (f = f + 32 | 0)) >= (0 | l) && b(32) : any
>s = f, (0 | (f = f + 32 | 0)) >= (0 | l) && b(32) : error
>s = f : error
>s : any
>f : error
>(0 | (f = f + 32 | 0)) >= (0 | l) && b(32) : any
>(0 | (f = f + 32 | 0)) >= (0 | l) && b(32) : error
>(0 | (f = f + 32 | 0)) >= (0 | l) : boolean
> : ^^^^^^^
>(0 | (f = f + 32 | 0)) : number
@@ -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;
};
@@ -191,7 +191,7 @@ let render = (ctrl, model) =>
> : ^^^^^^
{(!todo.editable) ?
>(!todo.editable) ? <input class="toggle" type="checkbox"></input> : null : any
>(!todo.editable) ? <input class="toggle" type="checkbox"></input> : null : error
>(!todo.editable) : boolean
> : ^^^^^^^
>!todo.editable : boolean
@@ -30,8 +30,8 @@ function f1(c1: Function, c2: () => object, callable: typeof c1 | typeof c2) {
> : ^^^^^^^^^^^^
const c = callable();
>c : any
>callable() : any
>c : error
>callable() : error
>callable : Function | (() => object)
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
}
@@ -43,8 +43,8 @@ function f2(fetcherParams: object | (() => object)) {
> : ^^^^^^^^^^^^^^^^ ^
const data = typeof fetcherParams === 'function'
>data : any
>typeof fetcherParams === 'function' ? fetcherParams() : fetcherParams : any
>data : error
>typeof fetcherParams === 'function' ? fetcherParams() : fetcherParams : error
>typeof fetcherParams === 'function' : boolean
> : ^^^^^^^
>typeof fetcherParams : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
@@ -55,7 +55,7 @@ function f2(fetcherParams: object | (() => object)) {
> : ^^^^^^^^^^
? fetcherParams()
>fetcherParams() : any
>fetcherParams() : error
>fetcherParams : Function | (() => object)
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -0,0 +1,5 @@
// @declaration: true
// @emitDeclarationOnly: true
export const object = {
foo: <T extends Set<T> | []>(): void => { },
};