carbon-components-svelte icon indicating copy to clipboard operation
carbon-components-svelte copied to clipboard

Allow null on TextArea

Open CordlessWool opened this issue 1 year ago • 4 comments

Allow null as value attribute on TextArea as on TextInput

CordlessWool avatar Mar 12 '24 14:03 CordlessWool

I think that it makes sense to loosen the value type to accept null so that it works in TypeScript strict mode.

If the Svelte language tools were actually strict, this would just create problems elsewhere. With null in the type, it should not be possible to bind:value to a string variable any more because null is not assignable to string.

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...

brunnerh avatar Mar 14 '24 06:03 brunnerh

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.

CordlessWool avatar Mar 20 '24 08:03 CordlessWool

Since when is null related to number, null is not 0.

That was exactly my point, null is not compatible with other types, which is why such assignments are not allowed by TS itself. The Svelte language tools (conveniently?) ignore this.

Pure TS example:

let componentProperty: string | null = {} as any;
let variableThatIsBound: string = {} as any;

variableThatIsBound = componentProperty;

Error on variableThatIsBound:

Type 'string | null' is not assignable to type 'string'.
  Type 'null' is not assignable to type 'string'.(2322)

brunnerh avatar Mar 20 '24 11:03 brunnerh

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.

CordlessWool avatar Mar 20 '24 19:03 CordlessWool

Fixed in v0.85.1

metonym avatar Aug 09 '24 13:08 metonym