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

Ignore silentNever in intersections with other meaningful constituents #60876

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17825,6 +17825,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function addTypeToIntersection(typeSet: Map<string, Type>, includes: TypeFlags, type: Type) {
if (type === silentNeverType) {
return includes;
}
Comment on lines +17828 to +17830
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes silentNeverType behave more like unknown in intersections. Which is definitely not correct for a never type... but a silentNeverType is really just a special marker type so it doesn't quite have to obey the rules.

const flags = type.flags;
if (flags & TypeFlags.Intersection) {
return addTypesToIntersection(typeSet, includes, (type as IntersectionType).types);
Expand Down
99 changes: 99 additions & 0 deletions tests/baselines/reference/silentNeverInIntersections1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//// [tests/cases/compiler/silentNeverInIntersections1.ts] ////

=== silentNeverInIntersections1.ts ===
// https://github.com/microsoft/TypeScript/issues/60864

class Variable<U, S extends string> {
>Variable : Symbol(Variable, Decl(silentNeverInIntersections1.ts, 0, 0))
>U : Symbol(U, Decl(silentNeverInIntersections1.ts, 2, 15))
>S : Symbol(S, Decl(silentNeverInIntersections1.ts, 2, 17))

constructor(public s: S) {}
>s : Symbol(Variable.s, Decl(silentNeverInIntersections1.ts, 3, 14))
>S : Symbol(S, Decl(silentNeverInIntersections1.ts, 2, 17))

u!: U;
>u : Symbol(Variable.u, Decl(silentNeverInIntersections1.ts, 3, 29))
>U : Symbol(U, Decl(silentNeverInIntersections1.ts, 2, 15))
}

function mkGeneric<U, S extends string>(s: S) {
>mkGeneric : Symbol(mkGeneric, Decl(silentNeverInIntersections1.ts, 5, 1))
>U : Symbol(U, Decl(silentNeverInIntersections1.ts, 7, 19))
>S : Symbol(S, Decl(silentNeverInIntersections1.ts, 7, 21))
>s : Symbol(s, Decl(silentNeverInIntersections1.ts, 7, 40))
>S : Symbol(S, Decl(silentNeverInIntersections1.ts, 7, 21))

return new Variable<U, S>(s);
>Variable : Symbol(Variable, Decl(silentNeverInIntersections1.ts, 0, 0))
>U : Symbol(U, Decl(silentNeverInIntersections1.ts, 7, 19))
>S : Symbol(S, Decl(silentNeverInIntersections1.ts, 7, 21))
>s : Symbol(s, Decl(silentNeverInIntersections1.ts, 7, 40))
}

type ExactArgNames<GenericType, Constraint> = GenericType & {
>ExactArgNames : Symbol(ExactArgNames, Decl(silentNeverInIntersections1.ts, 9, 1))
>GenericType : Symbol(GenericType, Decl(silentNeverInIntersections1.ts, 11, 19))
>Constraint : Symbol(Constraint, Decl(silentNeverInIntersections1.ts, 11, 31))
>GenericType : Symbol(GenericType, Decl(silentNeverInIntersections1.ts, 11, 19))

[K in keyof GenericType]: K extends keyof Constraint ? GenericType[K] : never;
>K : Symbol(K, Decl(silentNeverInIntersections1.ts, 12, 3))
>GenericType : Symbol(GenericType, Decl(silentNeverInIntersections1.ts, 11, 19))
>K : Symbol(K, Decl(silentNeverInIntersections1.ts, 12, 3))
>Constraint : Symbol(Constraint, Decl(silentNeverInIntersections1.ts, 11, 31))
>GenericType : Symbol(GenericType, Decl(silentNeverInIntersections1.ts, 11, 19))
>K : Symbol(K, Decl(silentNeverInIntersections1.ts, 12, 3))

};

type AllowVariables<T> =
>AllowVariables : Symbol(AllowVariables, Decl(silentNeverInIntersections1.ts, 13, 2))
>T : Symbol(T, Decl(silentNeverInIntersections1.ts, 15, 20))

| Variable<T, any>
>Variable : Symbol(Variable, Decl(silentNeverInIntersections1.ts, 0, 0))
>T : Symbol(T, Decl(silentNeverInIntersections1.ts, 15, 20))

| { [K in keyof T]: Variable<T[K], any> | T[K] };
>K : Symbol(K, Decl(silentNeverInIntersections1.ts, 17, 7))
>T : Symbol(T, Decl(silentNeverInIntersections1.ts, 15, 20))
>Variable : Symbol(Variable, Decl(silentNeverInIntersections1.ts, 0, 0))
>T : Symbol(T, Decl(silentNeverInIntersections1.ts, 15, 20))
>K : Symbol(K, Decl(silentNeverInIntersections1.ts, 17, 7))
>T : Symbol(T, Decl(silentNeverInIntersections1.ts, 15, 20))
>K : Symbol(K, Decl(silentNeverInIntersections1.ts, 17, 7))

type TestArgs = {
>TestArgs : Symbol(TestArgs, Decl(silentNeverInIntersections1.ts, 17, 51))

someArg: number;
>someArg : Symbol(someArg, Decl(silentNeverInIntersections1.ts, 19, 17))

};

type TestArgsWithVars = AllowVariables<TestArgs>;
>TestArgsWithVars : Symbol(TestArgsWithVars, Decl(silentNeverInIntersections1.ts, 21, 2))
>AllowVariables : Symbol(AllowVariables, Decl(silentNeverInIntersections1.ts, 13, 2))
>TestArgs : Symbol(TestArgs, Decl(silentNeverInIntersections1.ts, 17, 51))

function takesGeneric<V extends AllowVariables<TestArgs>>(
>takesGeneric : Symbol(takesGeneric, Decl(silentNeverInIntersections1.ts, 23, 49))
>V : Symbol(V, Decl(silentNeverInIntersections1.ts, 25, 22))
>AllowVariables : Symbol(AllowVariables, Decl(silentNeverInIntersections1.ts, 13, 2))
>TestArgs : Symbol(TestArgs, Decl(silentNeverInIntersections1.ts, 17, 51))

a: ExactArgNames<V, TestArgs>,
>a : Symbol(a, Decl(silentNeverInIntersections1.ts, 25, 58))
>ExactArgNames : Symbol(ExactArgNames, Decl(silentNeverInIntersections1.ts, 9, 1))
>V : Symbol(V, Decl(silentNeverInIntersections1.ts, 25, 22))
>TestArgs : Symbol(TestArgs, Decl(silentNeverInIntersections1.ts, 17, 51))

): void {}

let v = takesGeneric({ someArg: mkGeneric("x") });
>v : Symbol(v, Decl(silentNeverInIntersections1.ts, 29, 3))
>takesGeneric : Symbol(takesGeneric, Decl(silentNeverInIntersections1.ts, 23, 49))
>someArg : Symbol(someArg, Decl(silentNeverInIntersections1.ts, 29, 22))
>mkGeneric : Symbol(mkGeneric, Decl(silentNeverInIntersections1.ts, 5, 1))

89 changes: 89 additions & 0 deletions tests/baselines/reference/silentNeverInIntersections1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//// [tests/cases/compiler/silentNeverInIntersections1.ts] ////

=== silentNeverInIntersections1.ts ===
// https://github.com/microsoft/TypeScript/issues/60864

class Variable<U, S extends string> {
>Variable : Variable<U, S>
> : ^^^^^^^^^^^^^^

constructor(public s: S) {}
>s : S
> : ^

u!: U;
>u : U
> : ^
}

function mkGeneric<U, S extends string>(s: S) {
>mkGeneric : <U, S extends string>(s: S) => Variable<U, S>
> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^
>s : S
> : ^

return new Variable<U, S>(s);
>new Variable<U, S>(s) : Variable<U, S>
> : ^^^^^^^^^^^^^^
>Variable : typeof Variable
> : ^^^^^^^^^^^^^^^
>s : S
> : ^
}

type ExactArgNames<GenericType, Constraint> = GenericType & {
>ExactArgNames : ExactArgNames<GenericType, Constraint>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[K in keyof GenericType]: K extends keyof Constraint ? GenericType[K] : never;
};

type AllowVariables<T> =
>AllowVariables : AllowVariables<T>
> : ^^^^^^^^^^^^^^^^^

| Variable<T, any>
| { [K in keyof T]: Variable<T[K], any> | T[K] };

type TestArgs = {
>TestArgs : TestArgs
> : ^^^^^^^^

someArg: number;
>someArg : number
> : ^^^^^^

};

type TestArgsWithVars = AllowVariables<TestArgs>;
>TestArgsWithVars : TestArgsWithVars
> : ^^^^^^^^^^^^^^^^

function takesGeneric<V extends AllowVariables<TestArgs>>(
>takesGeneric : <V extends AllowVariables<TestArgs>>(a: ExactArgNames<V, TestArgs>) => void
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^

a: ExactArgNames<V, TestArgs>,
>a : ExactArgNames<V, TestArgs>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^

): void {}

let v = takesGeneric({ someArg: mkGeneric("x") });
>v : void
> : ^^^^
>takesGeneric({ someArg: mkGeneric("x") }) : void
> : ^^^^
>takesGeneric : <V extends AllowVariables<TestArgs>>(a: ExactArgNames<V, TestArgs>) => void
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
>{ someArg: mkGeneric("x") } : { someArg: Variable<number, "x">; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>someArg : Variable<number, "x">
> : ^^^^^^^^^^^^^^^^^^^^^
>mkGeneric("x") : Variable<number, "x">
> : ^^^^^^^^^^^^^^^^^^^^^
>mkGeneric : <U, S extends string>(s: S) => Variable<U, S>
> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^
>"x" : "x"
> : ^^^

33 changes: 33 additions & 0 deletions tests/cases/compiler/silentNeverInIntersections1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @strict: true
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/60864

class Variable<U, S extends string> {
constructor(public s: S) {}
u!: U;
}

function mkGeneric<U, S extends string>(s: S) {
return new Variable<U, S>(s);
}

type ExactArgNames<GenericType, Constraint> = GenericType & {
[K in keyof GenericType]: K extends keyof Constraint ? GenericType[K] : never;
};

type AllowVariables<T> =
| Variable<T, any>
| { [K in keyof T]: Variable<T[K], any> | T[K] };

type TestArgs = {
someArg: number;
};

type TestArgsWithVars = AllowVariables<TestArgs>;

function takesGeneric<V extends AllowVariables<TestArgs>>(
a: ExactArgNames<V, TestArgs>,
): void {}

let v = takesGeneric({ someArg: mkGeneric("x") });
Loading