News for hackers. Stuff that matters.
Re:Tricks I wish I knew when I learned TypeScript by nkingsy on Tuesday October 12, 2021 @12:25PM (#28841628)
I'm building a strongly typed form abstraction layer for work. I use code like this to express "if this generic can be undefined, this field is required. Otherwise it cannot be used".

So: FormElement<string|undefined> needs to have a "disabled" function, indicating conditions under which it becomes disabled (and absent from the model), while FormElement<string> must not have a disabled function, as it will always be present in the model.

One pitfall of this approach is it requires a lot of trial and error to find the incantation that both works and doesn't swallow error messages.

There are no comments on this comment yet.