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

If exactOptionalPropertyTypes: true, undefined is not allowed when using withDefault #20866

Closed
atlansien opened this issue May 16, 2023 · 1 comment

Comments

@atlansien
Copy link

Environment

Operating System: Darwin
Node Version: v18.0.0
Nuxt Version: 3.4.1
Nitro Version: 2.3.3
Package Manager: yarn@1.22.19
Builder: vite
User Config: -
Runtime Modules: -
Build Modules: -
IDE: VSCode 1.77.3
volar 1.2.0

Reproduction

https://stackblitz.com/edit/github-6rhv3z?file=components/Hoge.vue

Describe the bug

If exactOptionalPropertyTypes is set to true in tsconfig, then props implementations using withDefault will get an error when adding undefined to the type.

const props = withDefaults(
  defineProps<{
    hoge?: string | undefined;
  }>(),
  {
    hoge: undefined,
  },
);

The following error occurs

Argument of type '{ hoge: undefined; }' is not assignable to parameter of type 'InferDefaults<Readonly<Omit<{ hoge?: string | undefined; }, never> & {}>>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'hoge' are incompatible.ts(2379)

For now, we are using @ts-ignore or modifying the runtime declaration, but we would like to write it in type-based format if possible.

Additional context

No response

Logs

No response

Copy link
Member

This is an upstream vuejs/core issue: vuejs/core#6532

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants