Skip to content

Extending types / BaseColorVariant does not work, Type '"myvariant"' is not assignable to type 'keyof BaseColorVariant | null | undefined'. #1609

@sceee

Description

@sceee

Discussed in #1473

Originally posted by sceee September 22, 2023
Hi,

I'm trying to extend the BaseColorVariant type to reflect an additional color variant I defined in bootstrap sass.

Unfortunately, extending the types doesn't work as expected. I tried to follow the Extending types manual described here: https://bootstrap-vue-next.github.io/bootstrap-vue-next/docs/types.html#extending-types
When trying to use the new variant, I still get the typescript error:

Type '"myvariant"' is not assignable to type 'keyof BaseColorVariant | null | undefined'.

37     <BBadge variant="myvariant" />

The shims-bootstrap-vue-next.d.ts is added as follows:

declare module 'bootstrap-vue-next/dist/src/types' {
  export interface BaseColorVariant {
    myvariant: unknown
  }
  export interface BaseButtonVariant {
  }
  export interface BaseTextColorVariant {
  }
  export interface BaseSize {
  }
}

...and the file is added to the include array in the tsconfig.

Does anyone have an idea why this is not working?

Edit:
Actually doing this (changing declare module to start with node_modules/...) in shims-bootstrap-vue-next.d.ts does work:

declare module 'node_modules/bootstrap-vue-next/dist/src/types' {
  export interface BaseColorVariant {
    myvariant: unknown
  }
  export interface BaseButtonVariant {
  }
  export interface BaseTextColorVariant {
  }
  export interface BaseSize {
  }
}

I actually just "inferred" this from VS Code generating an import for BaseColorVariant automatically like this

import type { BaseColorVariant } from 'node_modules/bootstrap-vue-next/dist/src/types'

instead of generating an import like this

import type { BaseColorVariant } from 'bootstrap-vue-next/dist/src/types'

But according to the docs I guess something with the paths is messed up and it should actually work with declare module 'bootstrap-vue-next/dist/src/types' or am I wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    stale-exemptUse this to prevent auto-stalling of an issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions