Skip to content

Commit 7374e93

Browse files
authored
fix(types): fix ComponentCustomProps augmentation (#9468)
close #8376
1 parent 5ea8a8a commit 7374e93

File tree

7 files changed

+61
-6
lines changed

7 files changed

+61
-6
lines changed

packages/dts-built-test/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# dts built-package test
2+
3+
This package is private and for testing only. It is used to verify edge cases for external libraries that build their types using Vue core types - e.g. Vuetify as in [#8376](https://github.com/vuejs/core/issues/8376).
4+
5+
When running the `build-dts` task, this package's types are built alongside other packages. Then, during `test-dts-only` it is imported and used in [`packages/dts-test/built.test-d.ts`](https://github.com/vuejs/core/blob/main/packages/dts-test/built.test-d.ts) to verify that the built types work correctly.

packages/dts-built-test/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@vue/dts-built-test",
3+
"private": true,
4+
"types": "dist/dts-built-test.d.ts",
5+
"dependencies": {
6+
"@vue/shared": "workspace:*",
7+
"@vue/reactivity": "workspace:*",
8+
"vue": "workspace:*"
9+
},
10+
"version": "3.3.6"
11+
}

packages/dts-built-test/src/index.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineComponent } from 'vue'
2+
3+
const _CustomPropsNotErased = defineComponent({
4+
props: {},
5+
setup() {}
6+
})
7+
8+
// #8376
9+
export const CustomPropsNotErased =
10+
_CustomPropsNotErased as typeof _CustomPropsNotErased & {
11+
foo: string
12+
}

packages/dts-test/built.test-d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { CustomPropsNotErased } from '@vue/dts-built-test'
2+
import { expectType, describe } from './utils'
3+
4+
declare module 'vue' {
5+
interface ComponentCustomProps {
6+
custom?: number
7+
}
8+
}
9+
10+
// #8376 - custom props should not be erased
11+
describe('Custom Props not erased', () => {
12+
expectType<number | undefined>(new CustomPropsNotErased().$props.custom)
13+
})

packages/dts-test/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "dts-test",
33
"private": true,
44
"dependencies": {
5-
"vue": "workspace:*"
5+
"vue": "workspace:*",
6+
"@vue/dts-built-test": "workspace:*"
67
},
78
"version": "3.3.6"
89
}

packages/runtime-core/src/componentPublicInstance.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,9 @@ export type ComponentPublicInstance<
206206
> = {
207207
$: ComponentInternalInstance
208208
$data: D
209-
$props: Prettify<
210-
MakeDefaultsOptional extends true
211-
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
212-
: P & PublicProps
213-
>
209+
$props: MakeDefaultsOptional extends true
210+
? Partial<Defaults> & Omit<Prettify<P> & PublicProps, keyof Defaults>
211+
: Prettify<P> & PublicProps
214212
$attrs: Data
215213
$refs: Data
216214
$slots: UnwrapSlotsType<S>

pnpm-lock.yaml

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)