mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 12:32:08 -06:00
Fixed an issue with string mappings over generic intersections not being deferred in conditional types (#55856)
This commit is contained in:
parent
aa9b695344
commit
41ebfbf0aa
@ -18008,7 +18008,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
|
||||
function isPatternLiteralPlaceholderType(type: Type): boolean {
|
||||
if (type.flags & TypeFlags.Intersection) {
|
||||
return some((type as IntersectionType).types, t => !!(t.flags & (TypeFlags.Literal | TypeFlags.Null | TypeFlags.Undefined)) || isPatternLiteralPlaceholderType(t));
|
||||
return !isGenericType(type) && some((type as IntersectionType).types, t => !!(t.flags & (TypeFlags.Literal | TypeFlags.Nullable)) || isPatternLiteralPlaceholderType(t));
|
||||
}
|
||||
return !!(type.flags & (TypeFlags.Any | TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt)) || isPatternLiteralType(type);
|
||||
}
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
//// [tests/cases/conformance/types/literal/stringMappingDeferralInConditionalTypes.ts] ////
|
||||
|
||||
=== stringMappingDeferralInConditionalTypes.ts ===
|
||||
// https://github.com/microsoft/TypeScript/issues/55847
|
||||
|
||||
type A<S> = Lowercase<S & string> extends "foo" ? 1 : 0;
|
||||
>A : Symbol(A, Decl(stringMappingDeferralInConditionalTypes.ts, 0, 0))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 2, 7))
|
||||
>Lowercase : Symbol(Lowercase, Decl(lib.es5.d.ts, --, --))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 2, 7))
|
||||
|
||||
let x1: A<"foo"> = 1; // ok
|
||||
>x1 : Symbol(x1, Decl(stringMappingDeferralInConditionalTypes.ts, 3, 3))
|
||||
>A : Symbol(A, Decl(stringMappingDeferralInConditionalTypes.ts, 0, 0))
|
||||
|
||||
type B<S> = Lowercase<S & string> extends `f${string}` ? 1 : 0;
|
||||
>B : Symbol(B, Decl(stringMappingDeferralInConditionalTypes.ts, 3, 21))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 5, 7))
|
||||
>Lowercase : Symbol(Lowercase, Decl(lib.es5.d.ts, --, --))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 5, 7))
|
||||
|
||||
let x2: B<"foo"> = 1; // ok
|
||||
>x2 : Symbol(x2, Decl(stringMappingDeferralInConditionalTypes.ts, 6, 3))
|
||||
>B : Symbol(B, Decl(stringMappingDeferralInConditionalTypes.ts, 3, 21))
|
||||
|
||||
type C<S> = Capitalize<Lowercase<S & string>> extends "Foo" ? 1 : 0;
|
||||
>C : Symbol(C, Decl(stringMappingDeferralInConditionalTypes.ts, 6, 21))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 8, 7))
|
||||
>Capitalize : Symbol(Capitalize, Decl(lib.es5.d.ts, --, --))
|
||||
>Lowercase : Symbol(Lowercase, Decl(lib.es5.d.ts, --, --))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 8, 7))
|
||||
|
||||
let x3: C<"foo"> = 1; // ok
|
||||
>x3 : Symbol(x3, Decl(stringMappingDeferralInConditionalTypes.ts, 9, 3))
|
||||
>C : Symbol(C, Decl(stringMappingDeferralInConditionalTypes.ts, 6, 21))
|
||||
|
||||
type D<S extends string> = Capitalize<Lowercase<S>> extends "Foo" ? 1 : 0;
|
||||
>D : Symbol(D, Decl(stringMappingDeferralInConditionalTypes.ts, 9, 21))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 11, 7))
|
||||
>Capitalize : Symbol(Capitalize, Decl(lib.es5.d.ts, --, --))
|
||||
>Lowercase : Symbol(Lowercase, Decl(lib.es5.d.ts, --, --))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 11, 7))
|
||||
|
||||
let x4: D<"foo"> = 1; // ok
|
||||
>x4 : Symbol(x4, Decl(stringMappingDeferralInConditionalTypes.ts, 12, 3))
|
||||
>D : Symbol(D, Decl(stringMappingDeferralInConditionalTypes.ts, 9, 21))
|
||||
|
||||
type E<S> = Lowercase<`f${S & string}` & `${S & string}f`>;
|
||||
>E : Symbol(E, Decl(stringMappingDeferralInConditionalTypes.ts, 12, 21))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 14, 7))
|
||||
>Lowercase : Symbol(Lowercase, Decl(lib.es5.d.ts, --, --))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 14, 7))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 14, 7))
|
||||
|
||||
type F = E<""> extends "f" ? 1 : 0; // 1
|
||||
>F : Symbol(F, Decl(stringMappingDeferralInConditionalTypes.ts, 14, 59))
|
||||
>E : Symbol(E, Decl(stringMappingDeferralInConditionalTypes.ts, 12, 21))
|
||||
|
||||
type G<S> = E<S> extends "f" ? 1 : 0;
|
||||
>G : Symbol(G, Decl(stringMappingDeferralInConditionalTypes.ts, 15, 35))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 16, 7))
|
||||
>E : Symbol(E, Decl(stringMappingDeferralInConditionalTypes.ts, 12, 21))
|
||||
>S : Symbol(S, Decl(stringMappingDeferralInConditionalTypes.ts, 16, 7))
|
||||
|
||||
let x5: G<""> = 1; // ok
|
||||
>x5 : Symbol(x5, Decl(stringMappingDeferralInConditionalTypes.ts, 17, 3))
|
||||
>G : Symbol(G, Decl(stringMappingDeferralInConditionalTypes.ts, 15, 35))
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
//// [tests/cases/conformance/types/literal/stringMappingDeferralInConditionalTypes.ts] ////
|
||||
|
||||
=== stringMappingDeferralInConditionalTypes.ts ===
|
||||
// https://github.com/microsoft/TypeScript/issues/55847
|
||||
|
||||
type A<S> = Lowercase<S & string> extends "foo" ? 1 : 0;
|
||||
>A : A<S>
|
||||
|
||||
let x1: A<"foo"> = 1; // ok
|
||||
>x1 : 1
|
||||
>1 : 1
|
||||
|
||||
type B<S> = Lowercase<S & string> extends `f${string}` ? 1 : 0;
|
||||
>B : B<S>
|
||||
|
||||
let x2: B<"foo"> = 1; // ok
|
||||
>x2 : 1
|
||||
>1 : 1
|
||||
|
||||
type C<S> = Capitalize<Lowercase<S & string>> extends "Foo" ? 1 : 0;
|
||||
>C : C<S>
|
||||
|
||||
let x3: C<"foo"> = 1; // ok
|
||||
>x3 : 1
|
||||
>1 : 1
|
||||
|
||||
type D<S extends string> = Capitalize<Lowercase<S>> extends "Foo" ? 1 : 0;
|
||||
>D : D<S>
|
||||
|
||||
let x4: D<"foo"> = 1; // ok
|
||||
>x4 : 1
|
||||
>1 : 1
|
||||
|
||||
type E<S> = Lowercase<`f${S & string}` & `${S & string}f`>;
|
||||
>E : Lowercase<`f${S & string}` & `${S & string}f`>
|
||||
|
||||
type F = E<""> extends "f" ? 1 : 0; // 1
|
||||
>F : 1
|
||||
|
||||
type G<S> = E<S> extends "f" ? 1 : 0;
|
||||
>G : G<S>
|
||||
|
||||
let x5: G<""> = 1; // ok
|
||||
>x5 : 1
|
||||
>1 : 1
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
// @strict: true
|
||||
// @noEmit: true
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/55847
|
||||
|
||||
type A<S> = Lowercase<S & string> extends "foo" ? 1 : 0;
|
||||
let x1: A<"foo"> = 1; // ok
|
||||
|
||||
type B<S> = Lowercase<S & string> extends `f${string}` ? 1 : 0;
|
||||
let x2: B<"foo"> = 1; // ok
|
||||
|
||||
type C<S> = Capitalize<Lowercase<S & string>> extends "Foo" ? 1 : 0;
|
||||
let x3: C<"foo"> = 1; // ok
|
||||
|
||||
type D<S extends string> = Capitalize<Lowercase<S>> extends "Foo" ? 1 : 0;
|
||||
let x4: D<"foo"> = 1; // ok
|
||||
|
||||
type E<S> = Lowercase<`f${S & string}` & `${S & string}f`>;
|
||||
type F = E<""> extends "f" ? 1 : 0; // 1
|
||||
type G<S> = E<S> extends "f" ? 1 : 0;
|
||||
let x5: G<""> = 1; // ok
|
||||
Loading…
x
Reference in New Issue
Block a user