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

Can extends [any, any] but not generic which is exactly [any, any] (woks till 5.3.3 breaks from 5.4.5) #60299

Open
zedryas opened this issue Oct 21, 2024 · 3 comments

Comments

@zedryas
Copy link

zedryas commented Oct 21, 2024

πŸ”Ž Search Terms

generic, tuple extends

πŸ•— Version & Regression Information

This code works in the playground with typescript version 5.3.3 but breaks since version 5.4.5 (version between are not available in the playground)

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.3#code/C4TwDgpgBAIghsOUC8UDacBcUCMAaKAI2wCYCA6SgY2wGY0BdBgWACg3RIoAVCAZ2DdwEHAB5uUCAA9gEAHYATPlDhyQjAHwoobKHp6SZ8pekrkAlnIBmEAE5QASodmLlGNQVUgGFSl8YMUAD8jlDYchAAbnYcwlCyAjjavAJCkGLwiBpsAPQ5+gB6QWyxXCmCwiTizsbK-j5QALJwfADWNa4qaoza7iCeagxaqLr6EtIuJmhmljb2ThO1TS2tvuT1gSFO4VExrJzQCcAkyfwVkFWZcNmseYVBQA

πŸ’» Code

type Data = [a: 1, b: 2, ...c: 3[]]

type TestType1<T extends any[]> = 
    T extends [...infer R extends [any, any], ...any[]] ? R : never
type test1 = TestType1<Data>
//   ^?

type TestType2<T extends any[], Mask extends any[] = [any, any]> = 
    T extends [...infer R extends Mask, ...any[]] ? R : never
type test2 = TestType2<Data>
//   ^?

πŸ™ Actual behavior

When passing the Mask as a generic and trying to extends the tuple with it to extract the relevant part, the resulting tuple is well formed, but item types are replaced with any

πŸ™‚ Expected behavior

Expect that constraint on infer to works wether as an explicit form or a generic holding a type with the exact same form, which used to be the case priori to typescript 5.4 bu breaks since

Additional information about the issue

No response

@jcalz
Copy link
Contributor

jcalz commented Oct 21, 2024

looks like this was caused by #57362

@Andarist
Copy link
Contributor

I'll do some digging into it then πŸ˜›

@zedryas
Copy link
Author

zedryas commented Oct 22, 2024

@Andarist a nice use case (using version 5.3.3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants