Skip to content

Conversation

Mini-ghost
Copy link
Contributor

When I tried to edit my component, I encountered a type error:

const InputComponent = defineComponent({ render() { return withDirectives( createElementBlock( 'input', { 'onUpdate:modelValue': (event: string | number) => (modelValueWritable.value = event), readonly: props.readonly, disabled: props.disabled, }, null, 512 ), [[vModelText, modelValueWritable.value, void 0, props.modelModifiers]] ); }, });

The error message indicated that undefined cannot be assigned to type string:

Type 'undefined' is not assignable to type 'string'. 
截圖 2024-08-07 下午2 19 21

However, upon reviewing the code generated in the Playground and Vue's source code, I found that when DirectiveArguments has a length of 4, the third argument can indeed be undefined.

function render(_ctx, _cache, $props, $setup, $data, $options) { return _withDirectives((_openBlock(), _createElementBlock("input", { "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => (($setup.msg) = $event)) }, null, 512 /* NEED_PATCH */)), [ [ _vModelText, $setup.msg, void 0, { lazy: true } ] ]) }

Playground

This PR corrects the type definition to reflect this observation.

Thank you for taking the time to review this PR. If there's anything I overlooked, please let me know.

Copy link

github-actions bot commented Aug 7, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 90.2 kB 34.6 kB 31.2 kB
vue.global.prod.js 147 kB 54.1 kB 48.1 kB

Usages

Name Size Gzip Brotli
createApp 49.7 kB 19.5 kB 17.8 kB
createSSRApp 53.2 kB 21 kB 19.1 kB
defineCustomElement 51.9 kB 20.2 kB 18.5 kB
overall 63.2 kB 24.5 kB 22.3 kB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants