Skip to content

Fixes for tests #2

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

Merged
merged 8 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed name collision in recursiveConditionalCrash4
Fixed keys in `intrinsicTypeKinds` not matching type names in es5.lib.d.ts
Fixed `getIntrinsicMappingType` behaving incorrectly
Fixed incorrect baseline reference for `recursiveConditionalTypes`
Fixed incorrect baseline reference for `intrinsicTypes`
  • Loading branch information
james-pre committed Mar 12, 2025
commit 7ef54d94c0a776a93ae9f095106fae921069a215
10 changes: 5 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1413,9 +1413,9 @@ const intrinsicTypeKinds: ReadonlyMap<string, IntrinsicTypeKind> = new Map(Objec
Uncapitalize: IntrinsicTypeKind.Uncapitalize,
NoInfer: IntrinsicTypeKind.NoInfer,
Add: IntrinsicTypeKind.Add,
Sub: IntrinsicTypeKind.Sub,
Mul: IntrinsicTypeKind.Mul,
Div: IntrinsicTypeKind.Div,
Subtract: IntrinsicTypeKind.Sub,
Multiply: IntrinsicTypeKind.Mul,
Divide: IntrinsicTypeKind.Div,
Integer: IntrinsicTypeKind.Integer,
}));

Expand Down Expand Up @@ -18391,8 +18391,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
type.flags & TypeFlags.TemplateLiteral ? getTemplateLiteralType(...applyTemplateStringMapping(symbol, (type as TemplateLiteralType).texts, (type as TemplateLiteralType).types)) :
// Mapping<Mapping<T>> === Mapping<T>
type.flags & TypeFlags.StringMapping && symbol === type.symbol ? type :
type.flags & (TypeFlags.Any | TypeFlags.String | TypeFlags.StringMapping) || isGenericIndexType(type) ? (getBaseConstraintOfType(type)?.flags ?? 0) & TypeFlags.StringLike ? getStringMappingTypeForGenericType(symbol, type) :
getCalculationTypeForGenericType(symbol, [type]) :
type.flags & TypeFlags.Calculation ? getCalculationTypeForGenericType(symbol, [type]) :
type.flags & (TypeFlags.Any | TypeFlags.String | TypeFlags.StringMapping) || isGenericIndexType(type) ? getStringMappingTypeForGenericType(symbol, type) :
// This handles Mapping<`${number}`> and Mapping<`${bigint}`>
isPatternLiteralPlaceholderType(type) ? getStringMappingTypeForGenericType(symbol, getTemplateLiteralType(["", ""], [type])) :
type;
Expand Down
164 changes: 164 additions & 0 deletions tests/baselines/reference/intrinsicTypes.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,28 @@ intrinsicTypes.ts(42,5): error TS2322: Type 'string' is not assignable to type '
intrinsicTypes.ts(43,5): error TS2322: Type 'Uppercase<T>' is not assignable to type 'Uppercase<U>'.
Type 'T' is not assignable to type 'U'.
'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'string'.
intrinsicTypes.ts(61,20): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(76,17): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(77,20): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(78,18): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(93,22): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(94,25): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(95,23): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(110,22): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(111,25): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(112,23): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(127,20): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(128,23): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(129,21): error TS2344: Type 'string' does not satisfy the constraint 'number'.
intrinsicTypes.ts(147,5): error TS2322: Type 'number' is not assignable to type 'Add<T, U>'.
intrinsicTypes.ts(148,5): error TS2322: Type 'Multiply<T, U>' is not assignable to type 'Add<T, U>'.
Type 'number' is not assignable to type 'Add<T, U>'.
intrinsicTypes.ts(149,5): error TS2322: Type 'number' is not assignable to type 'Multiply<T, U>'.
intrinsicTypes.ts(150,5): error TS2322: Type 'Add<T, U>' is not assignable to type 'Multiply<T, U>'.
Type 'number' is not assignable to type 'Multiply<T, U>'.


==== intrinsicTypes.ts (25 errors) ====
type TU1 = Uppercase<'hello'>; // "HELLO"
type TU2 = Uppercase<'foo' | 'bar'>; // "FOO" | "BAR"
type TU3 = Uppercase<string>; // Uppercase<string>
Expand Down Expand Up @@ -81,4 +102,147 @@ intrinsicTypes.ts(43,5): error TS2322: Type 'Uppercase<T>' is not assignable to
function foo4<U extends string>(x: Uppercase<U>) {
return foo3(x);
}

type TI1 = Integer<3.5>; // 3
type TI2 = Integer<2.5 | 3.4>; // 2 | 3
type TI3 = Integer<number>; // number
type TI4 = Integer<any>; // any
type TI5 = Integer<never>; // never
type TI6 = Integer<'42'>; // Error
~~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.

type TA1 = Add<4, 2>; // 6
type TA2L = Add<4 | 5, 2>; // 6 | 7
type TA2R = Add<4, 2 | 3>; // 6 | 7
type TA2LR = Add<4 | 5, 2 | 3>; // 6 | 7 | 8
type TA3L = Add<number, 2>; // number
type TA3R = Add<4, number>; // number
type TA3LR = Add<number, number>; // number
type TA4L = Add<any, 2>; // any
type TA4R = Add<4, any>; // any
type TA4LR = Add<any, any>; // any
type TA5L = Add<never, 2>; // never
type TA5R = Add<4, never>; // never
type TA5LR = Add<never, never>; // never
type TA6L = Add<'4', 2>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
type TA6R = Add<4, '2'>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
type TA6LR = Add<'4', '2'>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.

type TS1 = Subtract<4, 2>; // 2
type TS2L = Subtract<4 | 5, 2>; // 2 | 3
type TS2R = Subtract<4, 2 | 3>; // 2 | 1
type TS2LR = Subtract<4 | 5, 2 | 3>; // 2 | 1 | 3
type TS3L = Subtract<number, 2>; // number
type TS3R = Subtract<4, number>; // number
type TS3LR = Subtract<number, number>; // number
type TS4L = Subtract<any, 2>; // any
type TS4R = Subtract<4, any>; // any
type TS4LR = Subtract<any, any>; // any
type TS5L = Subtract<never, 2>; // never
type TS5R = Subtract<4, never>; // never
type TS5LR = Subtract<never, never>; // never
type TS6L = Subtract<'4', 2>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
type TS6R = Subtract<4, '2'>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
type TS6LR = Subtract<'4', '2'>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.

type TM1 = Multiply<4, 2>; // 8
type TM2L = Multiply<4 | 5, 2>; // 8 | 10
type TM2R = Multiply<4, 2 | 3>; // 8 | 12
type TM2LR = Multiply<4 | 5, 2 | 3>; // 8 | 12 | 10 | 15
type TM3L = Multiply<number, 2>; // number
type TM3R = Multiply<4, number>; // number
type TM3LR = Multiply<number, number>; // number
type TM4L = Multiply<any, 2>; // any
type TM4R = Multiply<4, any>; // any
type TM4LR = Multiply<any, any>; // any
type TM5L = Multiply<never, 2>; // never
type TM5R = Multiply<4, never>; // never
type TM5LR = Multiply<never, never>; // never
type TM6L = Multiply<'4', 2>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
type TM6R = Multiply<4, '2'>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
type TM6LR = Multiply<'4', '2'>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.

type TD1 = Divide<4, 2>; // 2
type TD2L = Divide<4 | 5, 2>; // 2 | 2.5
type TD2R = Divide<4, 2 | 4>; // 2 | 1
type TD2LR = Divide<4 | 5, 2 | 4>; // 2 | 1 | 2.5 | 1.25
type TD3L = Divide<number, 2>; // number
type TD3R = Divide<4, number>; // number
type TD3LR = Divide<number, number>; // number
type TD4L = Divide<any, 2>; // any
type TD4R = Divide<4, any>; // any
type TD4LR = Divide<any, any>; // any
type TD5L = Divide<never, 2>; // never
type TD5R = Divide<4, never>; // never
type TD5LR = Divide<never, never>; // never
type TD6L = Divide<'4', 2>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
type TD6R = Divide<4, '2'>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
type TD6LR = Divide<'4', '2'>; // Error
~~~
!!! error TS2344: Type 'string' does not satisfy the constraint 'number'.
type TD7 = Divide<1, 0>; // never

type TIX1<S extends number> = Integer<S>;
type TIX2 = TIX1<4.2>; // 4
type TAX1<M extends number, N extends number> = Add<M, N>;
type TAX2 = TAX1<4, 2>; // 6
type TSX1<M extends number, N extends number> = Subtract<M, N>;
type TSX2 = TSX1<4, 2>; // 6
type TMX1<M extends number, N extends number> = Multiply<M, N>;
type TMX2 = TMX1<4, 2>; // 8
type TDX1<M extends number, N extends number> = Divide<M, N>;
type TDX2 = TDX1<4, 2>; // 2
type TAMX = Add<2, Multiply<5, 8>> // 42

function foo5<T extends number, U extends T>(s: number, x: Add<T, U>, y: Multiply<T, U>) {
s = x;
s = y;
x = s; // Error
~
!!! error TS2322: Type 'number' is not assignable to type 'Add<T, U>'.
x = y; // Error
~
!!! error TS2322: Type 'Multiply<T, U>' is not assignable to type 'Add<T, U>'.
!!! error TS2322: Type 'number' is not assignable to type 'Add<T, U>'.
y = s; // Error
~
!!! error TS2322: Type 'number' is not assignable to type 'Multiply<T, U>'.
y = x; // Error
~
!!! error TS2322: Type 'Add<T, U>' is not assignable to type 'Multiply<T, U>'.
!!! error TS2322: Type 'number' is not assignable to type 'Multiply<T, U>'.
}

function foo6<T extends 0 | 1>(x: Add<T, 3>) {
let s: 3 | 4 = x;
}

declare function foo7<T extends number>(x: Integer<T>): T;

function foo8<U extends number>(x: Integer<U>) {
return foo7(x);
}

164 changes: 82 additions & 82 deletions tests/baselines/reference/intrinsicTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,88 +231,88 @@ declare function foo1<T extends string, U extends T>(s: string, x: Uppercase<T>,
declare function foo2<T extends 'foo' | 'bar'>(x: Uppercase<T>): void;
declare function foo3<T extends string>(x: Uppercase<T>): T;
declare function foo4<U extends string>(x: Uppercase<U>): U;
declare type TI1 = Integer<3.5>;
declare type TI2 = Integer<2.5 | 3.4>;
declare type TI3 = Integer<number>;
declare type TI4 = Integer<any>;
declare type TI5 = Integer<never>;
declare type TI6 = Integer<'42'>;
declare type TA1 = Add<4, 2>;
declare type TA2L = Add<4 | 5, 2>;
declare type TA2R = Add<4, 2 | 3>;
declare type TA2LR = Add<4 | 5, 2 | 3>;
declare type TA3L = Add<number, 2>;
declare type TA3R = Add<4, number>;
declare type TA3LR = Add<number, number>;
declare type TA4L = Add<any, 2>;
declare type TA4R = Add<4, any>;
declare type TA4LR = Add<any, any>;
declare type TA5L = Add<never, 2>;
declare type TA5R = Add<4, never>;
declare type TA5LR = Add<never, never>;
declare type TA6L = Add<'4', 2>;
declare type TA6R = Add<4, '2'>;
declare type TA6LR = Add<'4', '2'>;
declare type TS1 = Subtract<4, 2>;
declare type TS2L = Subtract<4 | 5, 2>;
declare type TS2R = Subtract<4, 2 | 3>;
declare type TS2LR = Subtract<4 | 5, 2 | 3>;
declare type TS3L = Subtract<number, 2>;
declare type TS3R = Subtract<4, number>;
declare type TS3LR = Subtract<number, number>;
declare type TS4L = Subtract<any, 2>;
declare type TS4R = Subtract<4, any>;
declare type TS4LR = Subtract<any, any>;
declare type TS5L = Subtract<never, 2>;
declare type TS5R = Subtract<4, never>;
declare type TS5LR = Subtract<never, never>;
declare type TS6L = Subtract<'4', 2>;
declare type TS6R = Subtract<4, '2'>;
declare type TS6LR = Subtract<'4', '2'>;
declare type TM1 = Multiply<4, 2>;
declare type TM2L = Multiply<4 | 5, 2>;
declare type TM2R = Multiply<4, 2 | 3>;
declare type TM2LR = Multiply<4 | 5, 2 | 3>;
declare type TM3L = Multiply<number, 2>;
declare type TM3R = Multiply<4, number>;
declare type TM3LR = Multiply<number, number>;
declare type TM4L = Multiply<any, 2>;
declare type TM4R = Multiply<4, any>;
declare type TM4LR = Multiply<any, any>;
declare type TM5L = Multiply<never, 2>;
declare type TM5R = Multiply<4, never>;
declare type TM5LR = Multiply<never, never>;
declare type TM6L = Multiply<'4', 2>;
declare type TM6R = Multiply<4, '2'>;
declare type TM6LR = Multiply<'4', '2'>;
declare type TD1 = Divide<4, 2>;
declare type TD2L = Divide<4 | 5, 2>;
declare type TD2R = Divide<4, 2 | 4>;
declare type TD2LR = Divide<4 | 5, 2 | 4>;
declare type TD3L = Divide<number, 2>;
declare type TD3R = Divide<4, number>;
declare type TD3LR = Divide<number, number>;
declare type TD4L = Divide<any, 2>;
declare type TD4R = Divide<4, any>;
declare type TD4LR = Divide<any, any>;
declare type TD5L = Divide<never, 2>;
declare type TD5R = Divide<4, never>;
declare type TD5LR = Divide<never, never>;
declare type TD6L = Divide<'4', 2>;
declare type TD6R = Divide<4, '2'>;
declare type TD6LR = Divide<'4', '2'>;
declare type TD7 = Divide<1, 0>;
declare type TIX1<S extends number> = Integer<S>;
declare type TIX2 = TIX1<4.2>;
declare type TAX1<M extends number, N extends number> = Add<M, N>;
declare type TAX2 = TAX1<4, 2>;
declare type TSX1<M extends number, N extends number> = Subtract<M, N>;
declare type TSX2 = TSX1<4, 2>;
declare type TMX1<M extends number, N extends number> = Multiply<M, N>;
declare type TMX2 = TMX1<4, 2>;
declare type TDX1<M extends number, N extends number> = Divide<M, N>;
declare type TDX2 = TDX1<4, 2>;
declare type TAMX = Add<2, Multiply<5, 8>>;
type TI1 = Integer<3.5>;
type TI2 = Integer<2.5 | 3.4>;
type TI3 = Integer<number>;
type TI4 = Integer<any>;
type TI5 = Integer<never>;
type TI6 = Integer<'42'>;
type TA1 = Add<4, 2>;
type TA2L = Add<4 | 5, 2>;
type TA2R = Add<4, 2 | 3>;
type TA2LR = Add<4 | 5, 2 | 3>;
type TA3L = Add<number, 2>;
type TA3R = Add<4, number>;
type TA3LR = Add<number, number>;
type TA4L = Add<any, 2>;
type TA4R = Add<4, any>;
type TA4LR = Add<any, any>;
type TA5L = Add<never, 2>;
type TA5R = Add<4, never>;
type TA5LR = Add<never, never>;
type TA6L = Add<'4', 2>;
type TA6R = Add<4, '2'>;
type TA6LR = Add<'4', '2'>;
type TS1 = Subtract<4, 2>;
type TS2L = Subtract<4 | 5, 2>;
type TS2R = Subtract<4, 2 | 3>;
type TS2LR = Subtract<4 | 5, 2 | 3>;
type TS3L = Subtract<number, 2>;
type TS3R = Subtract<4, number>;
type TS3LR = Subtract<number, number>;
type TS4L = Subtract<any, 2>;
type TS4R = Subtract<4, any>;
type TS4LR = Subtract<any, any>;
type TS5L = Subtract<never, 2>;
type TS5R = Subtract<4, never>;
type TS5LR = Subtract<never, never>;
type TS6L = Subtract<'4', 2>;
type TS6R = Subtract<4, '2'>;
type TS6LR = Subtract<'4', '2'>;
type TM1 = Multiply<4, 2>;
type TM2L = Multiply<4 | 5, 2>;
type TM2R = Multiply<4, 2 | 3>;
type TM2LR = Multiply<4 | 5, 2 | 3>;
type TM3L = Multiply<number, 2>;
type TM3R = Multiply<4, number>;
type TM3LR = Multiply<number, number>;
type TM4L = Multiply<any, 2>;
type TM4R = Multiply<4, any>;
type TM4LR = Multiply<any, any>;
type TM5L = Multiply<never, 2>;
type TM5R = Multiply<4, never>;
type TM5LR = Multiply<never, never>;
type TM6L = Multiply<'4', 2>;
type TM6R = Multiply<4, '2'>;
type TM6LR = Multiply<'4', '2'>;
type TD1 = Divide<4, 2>;
type TD2L = Divide<4 | 5, 2>;
type TD2R = Divide<4, 2 | 4>;
type TD2LR = Divide<4 | 5, 2 | 4>;
type TD3L = Divide<number, 2>;
type TD3R = Divide<4, number>;
type TD3LR = Divide<number, number>;
type TD4L = Divide<any, 2>;
type TD4R = Divide<4, any>;
type TD4LR = Divide<any, any>;
type TD5L = Divide<never, 2>;
type TD5R = Divide<4, never>;
type TD5LR = Divide<never, never>;
type TD6L = Divide<'4', 2>;
type TD6R = Divide<4, '2'>;
type TD6LR = Divide<'4', '2'>;
type TD7 = Divide<1, 0>;
type TIX1<S extends number> = Integer<S>;
type TIX2 = TIX1<4.2>;
type TAX1<M extends number, N extends number> = Add<M, N>;
type TAX2 = TAX1<4, 2>;
type TSX1<M extends number, N extends number> = Subtract<M, N>;
type TSX2 = TSX1<4, 2>;
type TMX1<M extends number, N extends number> = Multiply<M, N>;
type TMX2 = TMX1<4, 2>;
type TDX1<M extends number, N extends number> = Divide<M, N>;
type TDX2 = TDX1<4, 2>;
type TAMX = Add<2, Multiply<5, 8>>;
declare function foo5<T extends number, U extends T>(s: number, x: Add<T, U>, y: Multiply<T, U>): void;
declare function foo6<T extends 0 | 1>(x: Add<T, 3>): void;
declare function foo7<T extends number>(x: Integer<T>): T;
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy