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

types(ComponentPublicInstance): fix generated props to keep ComponentCustomProps #9468

Merged
merged 5 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/dts-built-test/README.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.