News for hackers. Stuff that matters.
Re:Is your programming language unreasonable? (2015) by edflsafoiewq on Saturday October 10, 2020 @01:27PM (#24740416)
Typescript allows this

  const c = getCustomer();  // type is Customer | null
  const z : Customer = c;   // ERROR; incompatible types
  if (x === null) {
    // handle null
  } else {
    const y : Customer = c; // OK; knows c isn't null here
  }
Re:Is your programming language unreasonable? (2015) by throw_m239339 on Saturday October 10, 2020 @01:55PM (#24740628)
Well Typescript is really a static code analyser for Javascript and not a language, since it does nothing at runtime, and that's fine, its type system can catch a broad range of issues and improve code quality drastically. It's a huge godsend for big codebases. But afaik it doesn't guard against null by default.

A simpler example:

    declare type Foo = {name:String};
    declare function getFoo():Foo|null;

    const f = getFoo();
    if(f!==null) // mandatory or yields an error
        console.log(f.name);

But afaik it doesn't guard against null by default.