carbon-design-system / carbon-components-svelte

Svelte implementation of the Carbon Design System
https://svelte.carbondesignsystem.com
Apache License 2.0
2.68k stars 261 forks source link

fix(radio-button): allow `value` type to be a number #1868

Closed metonym closed 9 months ago

metonym commented 9 months ago

Fixes #1867

Currently, the RadioButton value is typed to only allow strings. This was inadvertence since the type definitions for the library are auto-generated. If no explicit type is annotated, the type generator will use its default type.

This PR fixes loosens the value type to allow strings and numbers. I'd prefer not to make this an any type as I believe there is value in strictness.

Without this change, the following code would run fine but produce type errors.

<script lang="ts">
  import { RadioButtonGroup, RadioButton } from "carbon-components-svelte";

  const plans = [1, 2, 3];

  let plan = plans[0];

  $: console.log("Selected plan", plan, typeof plan);
</script>

<RadioButtonGroup
  bind:selected={plan}
  on:change={(e) => {
    const selected = e.detail;
    console.log("on:change", selected, typeof selected);
  }}
>
  {#each plans as value (value)}
    <RadioButton {value} />
  {/each}
</RadioButtonGroup>
metonym commented 9 months ago

Fixed in v0.82.7