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

fix(runtime-core): incomplete type inferred by generic components #9652

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pfumagalli
Copy link

@pfumagalli pfumagalli commented Nov 21, 2023

close #9610
This fixes the wrong type inferred by defineProps(...) using generic components as outlined in #9610 (and related #9546, #9277)

@pikax
Copy link
Member

pikax commented Nov 28, 2023

@pfumagalli can you a test?

@pfumagalli
Copy link
Author

@pikax ... add? run? a test...

Sure, can you point me to an example on how types are tested here? Will be happy to comply once I see how those are dealt with!

@pikax
Copy link
Member

pikax commented Nov 28, 2023

@pfumagalli, sorry :D

Yes, add a test, probably in here: https://github.com/vuejs/core/blob/main/packages/dts-test/setupHelpers.test-d.ts

@pfumagalli
Copy link
Author

@pikax Fabulous, TSD, love it...

Give me a few hours to finish daytime work, and I'll get right on it!

@pfumagalli
Copy link
Author

@pikax test added, and verified that it does NOT pass without the supplied patch.

Thank you for pointing me in the right direction!

@pfumagalli
Copy link
Author

Hold on... This breaks some other DTS tests... Checking.

@pfumagalli
Copy link
Author

Consolidated fixes into a single commit (easier on the eyes).

@pfumagalli
Copy link
Author

@pikax this should be ready to go now!

Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 86.5 kB 32.9 kB 29.7 kB
vue.global.prod.js 132 kB 49.6 kB 44.5 kB

Usages

Name Size Gzip Brotli
createApp 48 kB 18.9 kB 17.2 kB
createSSRApp 51.2 kB 20.2 kB 18.4 kB
defineCustomElement 50.4 kB 19.7 kB 18 kB
overall 61.4 kB 23.7 kB 21.6 kB

Copy link
Member

@pikax pikax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only seems to work with full prop declaration, it does not seem to work with:

describe('defineProps w/ generics and runtime declarations', <T extends Record<
  string,
  any
>>() => {
  const props = defineProps({
    foo: {
      type: Object as PropType<T>,
      required: false,
      default: null
    },
    bar: {
      type: Object as PropType<T>,
      required: true
    },
    baz: Object as PropType<T>
  })
  expectType<T | null>(props.foo)
  expectType<T>(props.bar)
  expectType<T | undefined>(props.baz)

  // @ts-expect-error should not be a string
  expectType<string>(props.foo)
  // @ts-expect-error should not be a string
  expectType<string>(props.bar)
  // @ts-expect-error should not be a string
  expectType<string>(props.baz)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid/incomplete type inferred by generic components v-bind cannot be bound to a type wrapped by a Partial
3 participants