-
-
Notifications
You must be signed in to change notification settings - Fork 261
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(text-area): type value
prop as nullable
#1933
fix(text-area): type value
prop as nullable
#1933
Conversation
@@ -8,7 +8,7 @@ export interface TextAreaProps extends RestProps { | |||
* Specify the textarea value | |||
* @default "" | |||
*/ | |||
value?: string; | |||
value?: null | string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These files are generated and should not to be edited manually.
The property would need a @type {...}
annotation in the source code.
For reference, the property in TextInput
:
carbon-components-svelte/src/TextInput/TextInput.svelte
Lines 13 to 20 in 21b1d78
/** | |
* Specify the input value. | |
* | |
* `value` will be set to `null` if type="number" | |
* and the value is empty. | |
* @type {null | number | string} | |
*/ | |
export let value = ""; |
But, I do not think changing this at all makes sense.
The input only has null
to accommodate type="number"
(see documentation above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I first wanted to add it there, but then I was confused how it get the type if there is nothing defined before?
At least for the component it does not make a different if it is null or undefined, doesn't it? To put values in the user mabybe have to change the type or do a cast, without the need to, because the textarea component can handle null values as it do for undefined. That is currently our problem.
* Specify the textarea value. | ||
* | ||
* and the value is empty. | ||
* @type {null | string} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the comment be simplified to:
/**
* Specify the textarea value
* @type {null | string}
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it makes sense to loosen the value
type to accept null
so that it works in TypeScript strict mode.
Could you amend the JSDoc comment and run yarn build:docs
? Doing so will auto-generate the corresponding TypeScript definitions.
If the Svelte language tools were actually strict, this would just create problems elsewhere. If this were to cause errors on all existing bindings, I would be quite opposed to this, but it looks like this is not the case... |
Since when is null related to number, null is not 0. To be 100% sure I also made a short implementation and I didn't had any problems with combining null, undefinded and string in combination with a bind. TS is in strict mode. |
That was exactly my point, let componentProperty: string | null = {} as any;
let variableThatIsBound: string = {} as any;
variableThatIsBound = componentProperty; Error on
|
Yes and exacatly this is why we need null as option because we have a variable that could be null | undefined | string and this is not assign able to undefined | string. To handle undefiend or null will make no difference for the component. Undefiend will also not assign able to string and anyway it is allowed, so the component already handle it and you will be able to assign string to string | null. |
value
prop as nullable
Fixed in v0.85.1 |
Allow null as value attribute on TextArea as on TextInput