8000 Component props typing doesn't allow TypeScript `exactOptionalPropertyTypes` · Issue #2650 · bootstrap-vue-next/bootstrap-vue-next · GitHub
  • [go: up one dir, main page]

    Skip to content
    Component props typing doesn't allow TypeScript exactOptionalPropertyTypes #2650
    Open
    @gtbuchanan

    Description

    @gtbuchanan

    Describe the bug

    Most of the BootstrapVueNext component props are marked as optional, but the type definition is missing undefined. This prevents the value undefined from actually being passed to the props when exactOptionalPropertyTypes is enabled, which limits some usage scenarios. For example, this is not allowed:

    <template>
      <BFormGroup :invalid-feedback="invalidFeedback"></BFormGroup>
    </template>
    <script setup lang="ts">
    import { ref } from 'vue';
    
    const invalidFeedback = ref<string>();
    </script>

    vue-tsc reports the following type error:

    src/App.vue:2:4 - error TS2379: Argument of type '{ invalidFeedback: string | undefined; }' is not assignable to parameter of type '{ readonly contentCols?: boolean | Numberish; readonly labelCols?: boolean | Numberish; readonly labelAlign?: string; readonly ariaInvalid?: AriaInvalid; ... 26 more ...; readonly labelAlignXl?: string; } & VNodeProps & AllowedComponentProps & ComponentCustomProps & Record<...>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
      Type '{ invalidFeedback: string | undefined; }' is not assignable to type '{ readonly contentCols?: boolean | Numberish; readonly labelCols?: boolean | Numberish; readonly labelAlign?: string; readonly ariaInvalid?: AriaInvalid; ... 26 more ...; readonly labelAlignXl?: string; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
        Types of property 'invalidFeedback' are incompatible.
          Type 'string | undefined' is not assignable to type 'string'.
            Type 'undefined' is not assignable to type 'string'.
    
    2   <BFormGroup :invalid-feedback="invalidFeedback"></BFormGroup>
    

    Reproduction

    https://stackblitz.com/edit/github-8kyt3tva?file=src%2FApp.vue&view=editor

    Used Package Manager

    pnpm

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      bugSomething isn't workingstaleThere has been no additional replies or questions and the thread is assumed closed

      Type

      No type

      Projects

      No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        0