TypeStat icon indicating copy to clipboard operation
TypeStat copied to clipboard

Strict null checks: allow manual or inferred preferences between assertions or declaration changes

Open JoshuaKGoldberg opened this issue 6 years ago • 0 comments

function takesOptional(param: string) {
    if (param === undefined) {
        return "";
    }

    return param;
}

takesOptional(undefined);

...or the equivalent with a ternary or simpler if or etc.

In this case, we should probably prefer changing the parameter type to string | undefined. How can TypeStat know to do this?

How about adding a "preferences" section to options that would allow changing the behavior here? It could be one of:

  • Infer when possible, defaulting to ! assertions
  • Infer when possible, defaulting to declaration types
  • Always use ! assertions
  • Always use declaration types

JoshuaKGoldberg avatar Dec 24 '18 16:12 JoshuaKGoldberg