You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exclude<any
type subtraction
any but
all types except
Checked: #31579#29317
Suggestion
typeT00=Exclude<any,whatever>
T00 should be composed of any (all) types, except those types that are assignable to whatever
Use Cases
I definded a bunch of functions according to the following interface:
interfaceecafretni{(x:any,y:Q): any}
x literally takes any type, there's no possible narrowing down. Think of a general-purpose deep-copy function, for example. Q is some other interface I defined somewhere. Here's the use case: I had to change the order of the arguments of ecafretni to (y:Q, x:any) and I was wishing that TypeScript would point out all the (hundreds of) points where I was calling functions abiding by that interface, so that I woulnd't miss any. But it wouldn't because, of course, type Q is assignable to any and type any is assignable to Q.
So I came up with another type to use in the place of any: R = Exclude<any,Q>, and redefine ecafretni argument types as f(y:Q, x:R). But it's not working. It seems that R behaves the same way as any.
Examples
constf=function(x : Exclude<any,Number>){};constx:Number=4;constv=f(x);// TYPE MISMATCH !!!! (not caught by TypeScript)
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
Hi
Search Terms
Exclude<any
type subtraction
any but
all types except
Checked: #31579 #29317
Suggestion
T00
should be composed ofany
(all) types, except those types that are assignable towhatever
Use Cases
I definded a bunch of functions according to the following interface:
x
literally takes any type, there's no possible narrowing down. Think of a general-purpose deep-copy function, for example.Q
is some other interface I defined somewhere. Here's the use case: I had to change the order of the arguments ofecafretni
to(y:Q, x:any)
and I was wishing that TypeScript would point out all the (hundreds of) points where I was calling functions abiding by that interface, so that I woulnd't miss any. But it wouldn't because, of course, typeQ
is assignable toany
and typeany
is assignable toQ
.So I came up with another type to use in the place of
any
:R = Exclude<any,Q>
, and redefineecafretni
argument types asf(y:Q, x:R)
. But it's not working. It seems thatR
behaves the same way asany
.Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: