Skip to content

Commit

Permalink
fix(types): fix ComponentCustomProps augmentation (#9468)
Browse files Browse the repository at this point in the history
close #8376
  • Loading branch information
pikax committed Oct 24, 2023
1 parent 5ea8a8a commit 7374e93
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/dts-built-test/README.md
@@ -0,0 +1,5 @@
# dts built-package test

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).

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.
11 changes: 11 additions & 0 deletions packages/dts-built-test/package.json
@@ -0,0 +1,11 @@
{
"name": "@vue/dts-built-test",
"private": true,
"types": "dist/dts-built-test.d.ts",
"dependencies": {
"@vue/shared": "workspace:*",
"@vue/reactivity": "workspace:*",
"vue": "workspace:*"
},
"version": "3.3.6"
}
12 changes: 12 additions & 0 deletions packages/dts-built-test/src/index.ts
@@ -0,0 +1,12 @@
import { defineComponent } from 'vue'

const _CustomPropsNotErased = defineComponent({
props: {},
setup() {}
})

// #8376
export const CustomPropsNotErased =
_CustomPropsNotErased as typeof _CustomPropsNotErased & {
foo: string
}
13 changes: 13 additions & 0 deletions packages/dts-test/built.test-d.ts
@@ -0,0 +1,13 @@
import { CustomPropsNotErased } from '@vue/dts-built-test'
import { expectType, describe } from './utils'

declare module 'vue' {
interface ComponentCustomProps {
custom?: number
}
}

// #8376 - custom props should not be erased
describe('Custom Props not erased', () => {
expectType<number | undefined>(new CustomPropsNotErased().$props.custom)
})
3 changes: 2 additions & 1 deletion packages/dts-test/package.json
Expand Up @@ -2,7 +2,8 @@
"name": "dts-test",
"private": true,
"dependencies": {
"vue": "workspace:*"
"vue": "workspace:*",
"@vue/dts-built-test": "workspace:*"
},
"version": "3.3.6"
}
8 changes: 3 additions & 5 deletions packages/runtime-core/src/componentPublicInstance.ts
Expand Up @@ -206,11 +206,9 @@ export type ComponentPublicInstance<
> = {
$: ComponentInternalInstance
$data: D
$props: Prettify<
MakeDefaultsOptional extends true
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
: P & PublicProps
>
$props: MakeDefaultsOptional extends true
? Partial<Defaults> & Omit<Prettify<P> & PublicProps, keyof Defaults>
: Prettify<P> & PublicProps
$attrs: Data
$refs: Data
$slots: UnwrapSlotsType<S>
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7374e93

Please sign in to comment.