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(types): allow DirectiveArguments third parameter to accept undefined #11540

Merged
merged 1 commit into from
Aug 7, 2024

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

@edison1105 edison1105 added ready to merge The PR is ready to be merged. easy to merge labels Aug 7, 2024
@yyx990803 yyx990803 merged commit 1058ce8 into vuejs:main Aug 7, 2024
11 checks passed
@Mini-ghost Mini-ghost deleted the fix/withDirectives-type branch August 7, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants