-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Script Setup nullable prop type causes compile error #4868
Comments
The problem does not reproduce. After replacing App.vue with Errors.vue, everything is fine. Or maybe I missed something?:joy: |
I think he's referring to the generated JS as one is |
I have create a repo of the setup and description of the errors. Specifically the Login1 and Login2 pages provide default null prop values using the two different styles. The readme explains https://github.com/CamdenGonzalez/vue-inertia-typescript-laravel |
@posva OP is saying there are compile errors. I also can't reproduce any compile errors.
@CamdenGonzalez can you give the actual error messages? I still don't know what kind of error we are talking about. I can't run your repo right now (and it's a laravel mix project,hardly a small repro). |
Apologies, I don't honestly know how to quantify repo sizes. I infer from your comment that a laravel project would be considered a large repo. Prop with default null value - no errors <script setup lang="ts">
// No errors from this file - props are nullable as expected
import { PropType } from 'vue'
interface Item {
[key: string]: unknown
}
const props = defineProps({
status: {
type: String as PropType<string | Item | null>,
required: false,
default: null
}
})
</script> Prop with default null value - throws errors during watch <script setup lang="ts">
interface Item {
[key: string]: unknown
}
interface Props {
status?: string | Item | null
}
const props = withDefaults(defineProps<Props>(), {
status: null
})
</script> The error for the nullable prop in script setup TS2769: No overload matches this call.
The last overload gave the following error.
Type '{ type: (StringConstructor | ObjectConstructor | null)[]; required: false; default: null; }' is not assignable to type 'Prop<unknown, unknown> | null'.
Types of property 'type' are incompatible.
Type '(StringConstructor | ObjectConstructor | null)[]' is not assignable to type 'true | PropType<unknown> | null | undefined'.
Type '(StringConstructor | ObjectConstructor | null)[]' is not assignable to type 'PropConstructor<unknown>[]'.
Type 'StringConstructor | ObjectConstructor | null' is not assignable to type 'PropConstructor<unknown>'.
Type 'null' is not assignable to type 'PropConstructor<unknown>'.
``` |
Version
3.2.20
Reproduction link
sfc.vuejs.org/
Steps to reproduce
Run the SFC Playground code with
npm run dev
and the Errors.vue file will throw a build error.The NoErrors.vue file will not throw an error.
The only difference is the way nullable props are defined in script setup
What is expected?
Should compile without errors.
What is actually happening?
withDefaults(defineProps<Props>(), {
in script setup throws an error when<Props>
interface declaration includes thenull
type.The text was updated successfully, but these errors were encountered: