TypeScript error with generic component (regression in v3.2.46)
Vue version
3.2.47
Link to minimal reproduction
https://github.com/andrews05/vue-project
Steps to reproduce
- Initialise a new vue project with TypeScript.
- Enable
experimentalRfc436
in tsconfig.json. - Define a generic type on
script setup
and use it in a prop. - Try to use that prop.
What is expected?
No errors should be detected
What is actually happening?
TypeScript reports an error when accessing the generic prop
<script setup lang="ts" generic="ModelType">
const props = defineProps<{
model: ModelType
}>()
const m = props.model // Error here
</script>
Property 'model' does not exist on type 'Readonly<Omit<{ model: ModelType; }, [ModelType] extends [boolean | undefined] ? "model" : never> & { [K in keyof Pick<{ model: ModelType; }, [ModelType] extends [...] ? "model" : never>]-?: NotUndefined<...>; }>'.ts(2339)
System Info
System:
OS: macOS 13.2.1
CPU: (8) arm64 Apple M1 Pro
Memory: 618.25 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.14.0 - ~/.n/bin/node
Yarn: 1.22.19 - ~/.n/bin/yarn
npm: 9.3.1 - ~/.n/bin/npm
Browsers:
Firefox: 109.0.1
Safari: 16.3
npmPackages:
vue: ^3.2.47 => 3.2.47
Any additional comments?
The issue does not occur on v3.2.45 and earlier - it was introduced in v3.2.46.
Just stumbled upon the generics today (and am kinda excited 😄 )
Having also a trouble with the typing on the props, although they are typed correctly in the SFC template part.
It seems that the type magic in this declaration is causing some problems
(just did a quick check by replacing with export declare function defineProps<TypeProps>(): TypeProps
and at least that made the prop types available in the script again 🤷)
runtime-core.d.ts
-> i guess from here?
export declare function defineProps<TypeProps>(): Readonly<Omit<TypeProps, BooleanKey<TypeProps>> & {
[K in keyof Pick<TypeProps, BooleanKey<TypeProps>>]-?: NotUndefined<TypeProps[K]>;
}>;