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

The non-literal defaults aren't recognized correctly #23

Open
illright opened this issue Jan 16, 2021 · 1 comment
Open

The non-literal defaults aren't recognized correctly #23

illright opened this issue Jan 16, 2021 · 1 comment

Comments

@illright
Copy link

Imagine you have a JS file which exports some enum:

export default Object.freeze({
  TOP_LEFT: 'top left',
  TOP_RIGHT: 'top right',
});

You want your prop to be one of the values from that enum, so you write the following in your Svelte component:

<script>
  import ThatEnum from 'path/to/enum';
  /**
   * @type {typeof import('path/to/enum').default}
   */
  export let position = ThatEnum.TOP_LEFT;
</script>

The generated typings lack the information on the default value of this prop:

export interface ComponentProps {
  position?: typeof import("path/to/enum").default;
}
@illright
Copy link
Author

illright commented Jan 16, 2021

Consequently, the same problem occurs with Infinity and undefined as the default values for a prop, as those are global variables.
It is also spotted with components and other Svelte objects (e.g. transitions) as default values.

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

No branches or pull requests

1 participant