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

5.0.2 T extends GenericType<infer InferredType> no longer resolves as true #53415

Closed
markglattback opened this issue Mar 21, 2023 · 4 comments
Closed
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@markglattback
Copy link

markglattback commented Mar 21, 2023

Bug Report

In previous versions of TypeScript (including 5.0.0-beta), when working with Vue, component prop types could be inferred using the following ExtractProps type where T is a Vue component:

import type { ComponentOptions } from 'vue'

type ExtractProps<T> = T extends ComponentOptions<infer Props> ? Props : never

The returned type is now never.

🔎 Search Terms

infer, generic

🕗 Version & Regression Information

5.0.0-rc

  • This changed between versions 5.0.0-beta and 5.0.0-rc

💻 Code

import type { ComponentOptions } from 'vue'
import MyComponent from './MyComponent.vue'

type ExtractProps<T> = T extends ComponentOptions<infer Props> ? Props : never

type MyComponentProps = ExtractProps<typeof MyComponent> // never (but correctly returned Props in earlier versions of TS)

⏯ Playground Link

Working (4.9.5)

Broken (5.0.2)

🙁 Actual behavior

MyComponentProps is never

🙂 Expected behavior

MyComponentProps should be the inferred Props type

@markglattback markglattback changed the title 5.0.2 extends no longer resolves as true when condition includes an inferred generic argument 5.0.2 T extends Generic type<infer InferredType> no longer resolves as true Mar 21, 2023
@markglattback markglattback changed the title 5.0.2 T extends Generic type<infer InferredType> no longer resolves as true 5.0.2 T extends GenericType<infer InferredType> no longer resolves as true Mar 21, 2023
@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Mar 21, 2023
@RyanCavanaugh
Copy link
Member

We'd need a self-contained repro (i.e. 3-50 lines, none of which import the entirety of Vue) in order to determine if this is an intentional change or not.

@kasperpeulen
Copy link

@markglattback Why did you close this? I'm investigating this as well, this broke TS support for Vue in storybook.

@markglattback
Copy link
Author

markglattback commented May 26, 2023

@kasperpeulen whilst the old approach was no longer working with TS 5.0.x, the following has helped:

I stumbled across a comment from the author of Volar recommending vue-component-type-helpers to extract component types. I found that in our project it was dependent on having a d.ts file containing component types but otherwise works very well. In our case our d.ts file is generated by the unplugin-vue-components plugin.

We're also using Storybook 7 and have no issues with type inference using Meta<typeof MyComponent> or Story<typeof MyComponent>.

@kasperpeulen
Copy link

kasperpeulen commented May 26, 2023

@markglattback Thanks for that! That is really useful.

I opened a PR in storybook to use those type helpers:
storybookjs/storybook#22814

Weird that you don't have issues in storybook, we have multiple users report that it breaks with TS 5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

3 participants