Skip to content

Infer on tuples broken on nightly #42331

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

Closed
mikearnaldi opened this issue Jan 14, 2021 · 6 comments · Fixed by #42409
Closed

Infer on tuples broken on nightly #42331

mikearnaldi opened this issue Jan 14, 2021 · 6 comments · Fixed by #42409
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@mikearnaldi
Copy link

Bug Report

The latest nightly release breaks non distributive infer

🕗 Version & Regression Information

Bug introduced in the latest nighty release

💻 Code

type _R<T> = [T] extends [{ _R: (_: infer R) => void }] ? R : never
type _E<T> = [T] extends [{ _E: () => infer E }] ? E : never
type _A<T> = [T] extends [{ _A: () => infer A }] ? A : never

interface Sync<R, E, A> {
  _R: (_: R) => void
  _E: () => E
  _A: () => A
}

type R = _R<Sync<number, string, void>>
type E = _E<Sync<number, string, void>>
type A = _A<Sync<number, string, void>>

🙁 Actual behavior

R = never
E = never
A = never

https://www.typescriptlang.org/play?ts=4.2.0-dev.20210114#code/C4TwDgpgBA+gSgHgCoD4oF4oG0kF0oQAewEAdgCYDO2A3rHAFxQAUMTAlqQGYQBOUcAJQY0ANwD27clAC++APwCoTUhFF8AUKEiwAosjSYc+IiQrUsdGLqbNh6NJx79dshVFcq1m7dBgBBAwxsPAJiMipaWH9be0duPih-NyhFZK91Xg0NThJeLgBDAGNoAGUQUiKEOAAaDzr-NBoNKHpbNgE4qAkpFr1YkQ8+gIGHJI0ZbN8lTHgEcsqEUgBXAFsAIz46ymBeTgBzOp7yFBQtcGhXWf0FqpWNragdvdJD7skTs+nk2cDbpbWm14212ByOH1OGiAA

🙂 Expected behavior

R = number
E = string
A = void

https://www.typescriptlang.org/play?ts=4.2.0-beta#code/C4TwDgpgBA+gSgHgCoD4oF4oG0kF0oQAewEAdgCYDO2A3rHAFxQAUMTAlqQGYQBOUcAJQY0ANwD27clAC++APwCoTUhFF8AUKEiwAosjSYc+IiQrUsdGLqbNh6NJx79dshVFcq1m7dBgBBAwxsPAJiMipaWH9be0duPih-NyhFZK91Xg0NThJeLgBDAGNoAGUQUiKEOAAaDzr-NBoNKHpbNgE4qAkpFr1YkQ8+gIGHJI0ZbN8lTHgEcsqEUgBXAFsAIz46ymBeTgBzOp7yFBQtcGhXWf0FqpWNragdvdJD7skTs+nk2cDbpbWm14212ByOH1OGiAA

@r-cyr
Copy link

r-cyr commented Jan 14, 2021

I can reproduce it, last working build was 4.2.0-dev.20210112.

@mikearnaldi
Copy link
Author

It seems related to tuples, rewriting as:

type _R<T> = {t: T} extends {t: { _R: (_: infer R) => void }} ? R : never
type _E<T> = {t: T} extends {t: { _E: () => infer E }} ? E : never
type _A<T> = {t: T} extends {t: { _A: () => infer A }} ? A : never

interface Sync<R, E, A> {
  _R: (_: R) => void
  _E: () => E
  _A: () => A
}

type R = _R<Sync<number, string, void>>
type E = _E<Sync<number, string, void>>
type A = _A<Sync<number, string, void>>

Works on nightly too

@mikearnaldi
Copy link
Author

Well seems definitely related to tuples:

type X = [0] extends [infer A] ? A : never

X here is never instead of 0

@mikearnaldi mikearnaldi changed the title Non distributive infer broken in nightly Infer on tuples broken on nightly Jan 14, 2021
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 14, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.1 milestone Jan 14, 2021
@ahejlsberg
Copy link
Member

@weswigham Might this be caused by #42248?

@weswigham
Copy link
Member

Hm, must be? I'll have to see why it caused this, since unwrapping the tuples for the "is generic" checks doesn't seem like it should affect inference of infer variables. And add some coverage into our test suite since this is pretty common.

@jcalz
Copy link
Contributor

jcalz commented Mar 6, 2021

Is this related or unrelated?

type Hmm = [never] extends [infer T, ...any[]] ?
    [T, [never] extends [T] ? true : false]
    : never

// TS 4.1.5
// type Hmm = [never, true] ✔

// TS 4.2.2
// type Hmm = [never, false] ❌
// So T is inferred as never, but [never] extends [T] is false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants