Skip to content
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

add unknowntype to getConstraintOfTypeParameter #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14535,9 +14535,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function getConstraintOfTypeParameter(typeParameter: TypeParameter): Type | undefined {
return hasNonCircularBaseConstraint(typeParameter) ? getConstraintFromTypeParameter(typeParameter) : undefined;
if (!hasNonCircularBaseConstraint(typeParameter)) return undefined;
const constraint = getConstraintFromTypeParameter(typeParameter);
return constraint === undefined && strictNullChecks ? unknownType : constraint;
}

function isConstMappedType(type: MappedType, depth: number): boolean {
const typeVariable = getHomomorphicTypeVariable(type);
return !!typeVariable && isConstTypeVariable(typeVariable, depth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ class ErrImpl<E> {
}

declare const Err: typeof ErrImpl & (<T>() => T);
>Err : typeof ErrImpl & (<T>() => T)
> : ^^^^^^^^^^^^^^^^^^^ ^^^^^^^ ^
>Err : typeof ErrImpl & (<T extends unknown>() => T)
> : ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ ^
>ErrImpl : typeof ErrImpl
> : ^^^^^^^^^^^^^^

type ErrAlias<U> = typeof Err<U>;
>ErrAlias : { new (): ErrImpl<U>; prototype: ErrImpl<any>; } & (() => U)
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>Err : typeof ErrImpl & (<T>() => T)
> : ^^^^^^^^^^^^^^^^^^^ ^^^^^^^ ^
>Err : typeof ErrImpl & (<T extends unknown>() => T)
> : ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ ^

declare const e: ErrAlias<number>;
>e : { new (): ErrImpl<number>; prototype: ErrImpl<any>; } & (() => number)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ declare class Class<T> {
}

declare function fn<T>(): T;
>fn : <T>() => T
> : ^ ^^^^^^^
>fn : <T extends unknown>() => T
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^


type ClassAlias<T> = typeof Class<T>;
Expand All @@ -24,8 +24,8 @@ type ClassAlias<T> = typeof Class<T>;
type FnAlias<T> = typeof fn<T>;
>FnAlias : typeof fn<T>
> :
>fn : <T_1>() => T_1
> : ^^^^^^^^^^^
>fn : <T_1 extends unknown>() => T_1
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^

type Wat<T> = ClassAlias<T> & FnAlias<T>;
>Wat : Wat<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ const debuglog = function() {
return format.apply(null, arguments);
>format.apply(null, arguments) : string
> : ^^^^^^
>format.apply : { <T, R>(this: (this: T) => R, thisArg: T): R; <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R; }
> : ^^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^
>format.apply : { <T extends unknown, R extends unknown>(this: (this: T) => R, thisArg: T): R; <T extends unknown, A extends any[], R extends unknown>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R; }
> : ^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^ ^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^
>format : (f: any, ...args: any[]) => string
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>apply : { <T, R>(this: (this: T) => R, thisArg: T): R; <T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R; }
> : ^^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^
>apply : { <T extends unknown, R extends unknown>(this: (this: T) => R, thisArg: T): R; <T extends unknown, A extends any[], R extends unknown>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R; }
> : ^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^ ^^^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^
>arguments : IArguments
> : ^^^^^^^^^^

Expand Down

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions tests/baselines/reference/arrayFlatNoCrashInference.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

=== arrayFlatNoCrashInference.ts ===
function foo<T>(arr: T[], depth: number) {
>foo : <T>(arr: T[], depth: number) => FlatArray<T, 0 | 1 | -1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20>[]
> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>foo : <T extends unknown>(arr: T[], depth: number) => FlatArray<T, 0 | 1 | -1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20>[]
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>arr : T[]
> : ^^^
>depth : number
Expand All @@ -12,12 +12,12 @@ function foo<T>(arr: T[], depth: number) {
return arr.flat(depth);
>arr.flat(depth) : FlatArray<T, 0 | 1 | -1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20>[]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>arr.flat : <A, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]
> : ^ ^^ ^^^^^^^^^ ^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>arr.flat : <A extends unknown, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]
> : ^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>arr : T[]
> : ^^^
>flat : <A, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]
> : ^ ^^ ^^^^^^^^^ ^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>flat : <A extends unknown, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]
> : ^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>depth : number
> : ^^^^^^
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

=== arrayFlatNoCrashInferenceDeclarations.ts ===
function foo<T>(arr: T[], depth: number) {
>foo : <T>(arr: T[], depth: number) => FlatArray<T, 0 | 1 | -1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20>[]
> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>foo : <T extends unknown>(arr: T[], depth: number) => FlatArray<T, 0 | 1 | -1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20>[]
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>arr : T[]
> : ^^^
>depth : number
Expand All @@ -12,12 +12,12 @@ function foo<T>(arr: T[], depth: number) {
return arr.flat(depth);
>arr.flat(depth) : FlatArray<T, 0 | 1 | -1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20>[]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>arr.flat : <A, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]
> : ^ ^^ ^^^^^^^^^ ^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>arr.flat : <A extends unknown, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]
> : ^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>arr : T[]
> : ^^^
>flat : <A, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]
> : ^ ^^ ^^^^^^^^^ ^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>flat : <A extends unknown, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[]
> : ^ ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>depth : number
> : ^^^^^^
}
12 changes: 6 additions & 6 deletions tests/baselines/reference/arrayLiteralInference.types
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ const appTypeStylesWithError: Map<AppType, Array<AppStyle>> = new Map([
// Repro from #31204

declare function foo<T>(...args: T[]): T[];
>foo : <T>(...args: T[]) => T[]
> : ^ ^^^^^ ^^ ^^^^^
>foo : <T extends unknown>(...args: T[]) => T[]
> : ^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>args : T[]
> : ^^^

Expand All @@ -192,8 +192,8 @@ let b1: { x: boolean }[] = foo({ x: true }, { x: false });
> : ^^^^^^^
>foo({ x: true }, { x: false }) : ({ x: true; } | { x: false; })[]
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>foo : <T>(...args: T[]) => T[]
> : ^ ^^^^^ ^^ ^^^^^
>foo : <T extends unknown>(...args: T[]) => T[]
> : ^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>{ x: true } : { x: true; }
> : ^^^^^^^^^^^^
>x : true
Expand All @@ -212,8 +212,8 @@ let b2: boolean[][] = foo([true], [false]);
> : ^^^^^^^^^^^
>foo([true], [false]) : (true[] | false[])[]
> : ^^^^^^^^^^^^^^^^^^^^
>foo : <T>(...args: T[]) => T[]
> : ^ ^^^^^ ^^ ^^^^^
>foo : <T extends unknown>(...args: T[]) => T[]
> : ^ ^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>[true] : true[]
> : ^^^^^^
>true : true
Expand Down
16 changes: 8 additions & 8 deletions tests/baselines/reference/assertionFunctionWildcardImport2.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

=== asserts.ts ===
function isNonNullable<T>(obj: T): asserts obj is NonNullable<T> {
>isNonNullable : <T>(obj: T) => asserts obj is NonNullable<T>
> : ^ ^^ ^^ ^^^^^
>isNonNullable : <T extends unknown>(obj: T) => asserts obj is NonNullable<T>
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>obj : T
> : ^

Expand Down Expand Up @@ -33,8 +33,8 @@ function isNonNullable<T>(obj: T): asserts obj is NonNullable<T> {

export {
isNonNullable
>isNonNullable : <T>(obj: T) => asserts obj is NonNullable<T>
> : ^ ^^ ^^ ^^^^^
>isNonNullable : <T extends unknown>(obj: T) => asserts obj is NonNullable<T>
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^

};

Expand All @@ -52,12 +52,12 @@ function test(obj: string | null): void {
asserts.isNonNullable(obj);
>asserts.isNonNullable(obj) : void
> : ^^^^
>asserts.isNonNullable : <T>(obj: T) => asserts obj is NonNullable<T>
> : ^ ^^ ^^ ^^^^^
>asserts.isNonNullable : <T extends unknown>(obj: T) => asserts obj is NonNullable<T>
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>asserts : typeof asserts
> : ^^^^^^^^^^^^^^
>isNonNullable : <T>(obj: T) => asserts obj is NonNullable<T>
> : ^ ^^ ^^ ^^^^^
>isNonNullable : <T extends unknown>(obj: T) => asserts obj is NonNullable<T>
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>obj : string | null
> : ^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Animal = Cat | Dog;
> : ^^^^^^

declare function assertEqual<T>(value: any, type: T): asserts value is T;
>assertEqual : <T>(value: any, type: T) => asserts value is T
> : ^ ^^ ^^ ^^ ^^ ^^^^^
>assertEqual : <T extends unknown>(value: any, type: T) => asserts value is T
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^
>value : any
>type : T
> : ^
Expand All @@ -55,8 +55,8 @@ const animal = { type: 'cat', canMeow: true } as Animal;
assertEqual(animal.type, 'cat' as const);
>assertEqual(animal.type, 'cat' as const) : void
> : ^^^^
>assertEqual : <T>(value: any, type: T) => asserts value is T
> : ^ ^^ ^^ ^^ ^^ ^^^^^
>assertEqual : <T extends unknown>(value: any, type: T) => asserts value is T
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^
>animal.type : "cat" | "dog"
> : ^^^^^^^^^^^^^
>animal : Animal
Expand Down Expand Up @@ -95,8 +95,8 @@ const animalOrUndef = { type: 'cat', canMeow: true } as Animal | undefined;
assertEqual(animalOrUndef?.type, 'cat' as const);
>assertEqual(animalOrUndef?.type, 'cat' as const) : void
> : ^^^^
>assertEqual : <T>(value: any, type: T) => asserts value is T
> : ^ ^^ ^^ ^^ ^^ ^^^^^
>assertEqual : <T extends unknown>(value: any, type: T) => asserts value is T
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^
>animalOrUndef?.type : "cat" | "dog" | undefined
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
>animalOrUndef : Animal | undefined
Expand Down
24 changes: 12 additions & 12 deletions tests/baselines/reference/assertionTypePredicates1.types
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ declare function assertIsArrayOfStrings(value: unknown): asserts value is string
> : ^^^^^^^

declare function assertDefined<T>(value: T): asserts value is NonNullable<T>;
>assertDefined : <T>(value: T) => asserts value is NonNullable<T>
> : ^ ^^ ^^ ^^^^^
>assertDefined : <T extends unknown>(value: T) => asserts value is NonNullable<T>
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>value : T
> : ^

Expand Down Expand Up @@ -262,8 +262,8 @@ function f01(x: unknown) {
assertDefined(x);
>assertDefined(x) : void
> : ^^^^
>assertDefined : <T>(value: T) => asserts value is NonNullable<T>
> : ^ ^^ ^^ ^^^^^
>assertDefined : <T extends unknown>(value: T) => asserts value is NonNullable<T>
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>x : string | undefined
> : ^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -390,8 +390,8 @@ function f02(x: string | undefined) {
assertDefined(x);
>assertDefined(x) : void
> : ^^^^
>assertDefined : <T>(value: T) => asserts value is NonNullable<T>
> : ^ ^^ ^^ ^^^^^
>assertDefined : <T extends unknown>(value: T) => asserts value is NonNullable<T>
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>x : string | undefined
> : ^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -445,8 +445,8 @@ namespace Debug {
> : ^^^^^^^^^^^^^^^^^^

export declare function assertDefined<T>(value: T): asserts value is NonNullable<T>;
>assertDefined : <T>(value: T) => asserts value is NonNullable<T>
> : ^ ^^ ^^ ^^^^^
>assertDefined : <T extends unknown>(value: T) => asserts value is NonNullable<T>
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>value : T
> : ^
}
Expand Down Expand Up @@ -528,12 +528,12 @@ function f10(x: string | undefined) {
Debug.assertDefined(x);
>Debug.assertDefined(x) : void
> : ^^^^
>Debug.assertDefined : <T>(value: T) => asserts value is NonNullable<T>
> : ^ ^^ ^^ ^^^^^
>Debug.assertDefined : <T extends unknown>(value: T) => asserts value is NonNullable<T>
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>Debug : typeof Debug
> : ^^^^^^^^^^^^
>assertDefined : <T>(value: T) => asserts value is NonNullable<T>
> : ^ ^^ ^^ ^^^^^
>assertDefined : <T extends unknown>(value: T) => asserts value is NonNullable<T>
> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^
>x : string | undefined
> : ^^^^^^^^^^^^^^^^^^

Expand Down
Loading
Loading