-
-
Notifications
You must be signed in to change notification settings - Fork 196
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 contructor's props
should be required if they contain a required prop
#1578
Comments
Can you give a reproducible? Not sure what exactly is going on there. |
Sorry, I thought this is a general issue since I never saw it working. I tried to create a fresh repo but cannot reproduce it there. Then I have deleted my The Anyhow, I still don't get an error if I don't set the I was thinking about having type definitions like this: interface ComponentConstructorOptionsWithoutProps {
target: Element | ShadowRoot;
anchor?: Element;
context?: Map<any, any>;
hydrate?: boolean;
intro?: boolean;
$$inline?: boolean;
}
interface ComponentConstructorOptionsWithProps<Props extends Record<string, any> = Record<string, any>> extends ComponentConstructorOptionsWithoutProps {
props: Props;
}
type ComponentConstructorOptions<Props extends Record<string, any> | never = never> = Props extends never
? ComponentConstructorOptionsWithoutProps
: ComponentConstructorOptionsWithProps<Props>; |
props
should be typed correctlyprops
should be required if they contain a required prop
Mhm right, the |
Yes I was also assuming that this would be a breaking change. Not sure if I understood it correctly but the language tools could "patch" the types without the Svelte-typings to change right? Ah, and what I forgot in the example above is the following type: interface ComponentConstructorOptionsWithOptionalProps<Props extends Record<string, any> = Record<string, any>> extends ComponentConstructorOptionsWithoutProps {
props?: Props;
} So in the end there should be three cases:
|
I have updated the description
Description
When using the JavaScript API to instantiate a Svelte component, I would find it useful to get an error if I forget to pass props.
In this case the
Component
has a required prop calledtitle
that expects astring
.I can completely omit the
props
attribute and won't get an error.Proposed solution
Type the
params
object of theComponentConstructorOptions
to get errors when instantiating a component incorrectly.Alternatives
No response
Additional Information, eg. Screenshots
No response
The text was updated successfully, but these errors were encountered: