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

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

Merged
merged 1 commit into from
Dec 17, 2023

Conversation

metonym
Copy link
Collaborator

@metonym metonym commented Dec 17, 2023

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 metonym merged commit 4792257 into master Dec 17, 2023
3 checks passed
@metonym metonym deleted the radio-button-types branch December 17, 2023 17:42
@metonym
Copy link
Collaborator Author

metonym commented Dec 17, 2023

Fixed in v0.82.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RadioButton value type should allow numbers
1 participant