-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Functioning NoInfer behavior in generic conditional types #57050
Comments
Those results are as expected. No inferences are made from the |
So here the "No" in "NoInfer" stands for "No!", as in "Veto". It's not uncoupled. |
You were expecting |
|
Using the test file below some good and some confusing (only to me) results were obtained: Without any
After adding type T10s = G10<A1<string> & B1<string>>;
>T10s : string // WANTED
type T11s = G10<A1<string> | B1<string>>;
>T11s : never // NOT WANTED and then the Finally I can do as @fatcerberus wisely suggests, without using
to get
which does indeed work perfectly. And although it is a bit verbose, it is applicable without leaving any trace of That cleared up my understanding of Test Filetest file // @strict: true
// @declaration: true
// @target: esnext
interface A<T> {
t:T;
f(x:T):T;
[Symbol.iterator]():IterableIterator<T>;
}
interface B<T> {
t:T;
f(x:T):T;
[Symbol.iterator]():IterableIterator<B<T>>;
}
type G01<AB> = AB extends A<infer U> & B<infer U> ? U : never;
type G02<AB> = AB extends A<infer U> | B<infer U> ? U : never;
type T01 = G01<A<string> & B<string>>;
type T02 = G02<A<string> | B<string>>;
interface A1<T> {
t:T;
f(x:T):T;
[Symbol.iterator]():IterableIterator<NoInfer<T>>;
}
interface B1<T> {
t:T;
f(x:T):T;
[Symbol.iterator]():IterableIterator<B<NoInfer<T>>>;
}
type G10<AB> = AB extends A1<infer U> & B1<infer U> ? U : never;
type G11<AB> = AB extends A1<infer U> | B1<infer U> ? U : never;
type T10s = G10<A1<string> & B1<string>>;
type T11s = G10<A1<string> | B1<string>>;
type RemIter<X extends {[Symbol.iterator]:any} > = Omit<X, typeof Symbol.iterator>;
type RemIterA<T> = Omit<A<T>, typeof Symbol.iterator>;
type RemIterB<T> = Omit<B<T>, typeof Symbol.iterator>;
type G20<AB> = AB extends RemIterA<infer U> & RemIterB<infer U> ? U : never;
type G21<AB> = AB extends RemIterA<infer U> | RemIterB<infer U> ? U : never;
type T20s = G20<A<string> & B<string>>;
type T21s = G21<A<string> | B<string>>; |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
issue #14829
pull #56794 (The pull for 14829)
β Viability Checklist
β Suggestion
These are conditional type examples in the 2.8 release doc:
The proposal is that the such generic types support
NoInfer
, for example:π Motivating Example
Testing the latest dev version with pull #56794, these results were obtained:
The location marked with <- WAS EXPECTING STRING show results of
never
wherestring
was expected.π» Use Cases
The text was updated successfully, but these errors were encountered: