Under Review
over 1 year ago

bug: const X = null as Array; doesn't give an error with strict typecheck

When I compile with -l 3 the following line should give an error:

const X = null as Array<Number>;

same for:

const Y = null as Number;

SDK: 4.1.7

  • > Y is const not var, should have assigned value because is defined once

    Good point! I wonder if it works differently for var.

    Either way, it seems inconsistent.

  • Y is const not var, should have assigned value because is defined once

  • > null is null, for every type... do you need null for Number?

    I think the point is if you want Y to be Number or null, you have to type something like:

    const Y = null as Number or Null;

    or

    const Y = null as Number?;

    (const Y = null as Number will fail to compile)

    By the same logic, if you want X to be an Array<Number> or null, you should have to type something like:

    const X = null as Array<Number> or Null;

    or

    const X = null as Array<Number>?;

    But in this case, const X = null as Array<Number> does compile.

    It's not consistent.

  • null is null, for every type... do you need null for Number?