TypeScript Version: 2.2.1
It seems that TS 2.2.1 changed the behavior of nullable parameters (NOTE: null specifically, not undefined) with defaults when compiling with --strictNullChecks. Was this change intentional? It's a breaking change.
I imagine this is a consequence of #12033, but AFAICT affecting null was likely an unintentional side effect.
Code
type OptionalString = string | null | undefined;
function hasDefault(val: OptionalString = "") {
// TS 2.1.6, type of val is OptionalString
// TS 2.2.1, type of val is string
}
// TS 2.1.6, next line compiled fine
// TS 2.2.1, error TS2345: Argument of type 'null' is not assignable to parameter of type 'string | undefined'.
hasDefault(null);
Expected behavior:
Type of val to be OptionalString (or string | null) and for null to be an accepted parameter.
Actual behavior:
Type of val is string and null is not accepted as an argument to the function.
TypeScript Version: 2.2.1
It seems that TS 2.2.1 changed the behavior of nullable parameters (NOTE:
nullspecifically, notundefined) with defaults when compiling with--strictNullChecks. Was this change intentional? It's a breaking change.I imagine this is a consequence of #12033, but AFAICT affecting
nullwas likely an unintentional side effect.Code
Expected behavior:
Type of val to be
OptionalString(orstring | null) and fornullto be an accepted parameter.Actual behavior:
Type of val is
stringandnullis not accepted as an argument to the function.