News for hackers. Stuff that matters.
Re:Using TypeScript with React by ht85 on Thursday August 22, 2019 @09:43AM (#20767942)
Could you give an example of the kind of problem you're talking about?
Re:Using TypeScript with React by collyw on Thursday August 22, 2019 @11:46AM (#20769376)
I am trying to remember the error that I got. I think it was complaining that the variable being passed to a function may be a null rather than the type that was specified.
Re:Using TypeScript with React by tuxracer on Thursday August 22, 2019 @01:25PM (#20770402)
Doesn't sound like a problem you get with typing, sounds like it was actually catching what could be a runtime error in production. If the variable is possibly null but the function you're passing it to expects it to not be null then typescript is pointing out what could be a runtime error if you don't explicitly handle that case (if (!foo) ...)
Re:Using TypeScript with React by SenHeng on Thursday August 22, 2019 @01:18PM (#20770330)
Sounds like an optional variable.

    function fn(arg?: SomeObject)
Or worst still, an or undefined, often found in class variables.

    this.foo: Thing | undefined = undefined;
Easy way to sidestep this error is > if (!arg) return;, but it’s really a code smell of a larger, design issue. As in, the function shouldn’t really be depending on an optional value.