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

Exported optional null types have incorrect typescript type in the downloaded NPM package #175

Closed
jchen42703 opened this issue Jun 24, 2024 · 1 comment
Labels
help wanted Extra attention is needed PR-welcome

Comments

@jchen42703
Copy link

jchen42703 commented Jun 24, 2024

Problem Description

For example, for the SveltyPicker:

When optional null types are exported using JSDoc like:

SveltyPicker.svelte

  /** @type {string|string[]|null} */
  export let value = null;
  /** @type {Date|Date[]|null} */
  export let initialDate = null;

The resulting typescript types are:

SveltyPicker.svelte.d.ts

 value?: string | string[];
 initialDate?: Date | Date[];

These are not the same types at all! The JS type assumes that the type is optional and defaults to null BUT the typescript example assumes the values default to undefined.

This has been the cause of a copy nasty validation bugs on our end because the type checker incorrectly tells you to change your default value to undefined, which causes our optional checks to fail.

Solution

No clue why the type exporter does this tbh...

@mskocik mskocik added help wanted Extra attention is needed PR-welcome labels Aug 7, 2024
@mskocik
Copy link
Owner

mskocik commented Dec 12, 2024

Check the latest (v5.2.11) version with corrected types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed PR-welcome
Projects
None yet
Development

No branches or pull requests

2 participants