Skip to content

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

Open
pfumagalli wants to merge 1 commit intovuejs:mainfrom
pfumagalli:main
Open

fix(runtime-core): incomplete type inferred by generic components#9652
pfumagalli wants to merge 1 commit intovuejs:mainfrom
pfumagalli:main

Conversation

@pfumagalli
Copy link
Copy Markdown

@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
Copy Markdown
Member

pikax commented Nov 28, 2023

@pfumagalli can you a test?

@pfumagalli
Copy link
Copy Markdown
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
Copy Markdown
Member

pikax commented Nov 28, 2023

@pfumagalli
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

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

@pfumagalli
Copy link
Copy Markdown
Author

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

@pfumagalli
Copy link
Copy Markdown
Author

@pikax this should be ready to go now!

@github-actions
Copy link
Copy Markdown

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
Copy Markdown
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