3.7 Breaking Changes
DOM Changes
Types in lib.dom.d.ts
have been updated.These changes are largely correctness changes related to nullability, but impact will ultimately depend on your codebase.
Class Field Mitigations
As mentioned above, TypeScript 3.7 emits get
/set
accessors in .d.ts
files which can cause breaking changes for consumers on older versions of TypeScript like 3.5 and prior.TypeScript 3.6 users will not be impacted, since that version was future-proofed for this feature.
While not a breakage per se, opting in to the useDefineForClassFields
flag can cause breakage when:
- overriding an accessor in a derived class with a property declaration
- re-declaring a property declaration with no initializerTo understand the full impact, read the section above on the
useDefineForClassFields
flag.
Function Truthy Checks
As mentioned above, TypeScript now errors when functions appear to be uncalled within if
statement conditions.An error is issued when a function type is checked in if
conditions unless any of the following apply:
- the checked value comes from an optional property
strictNullChecks
is disabled- the function is later called within the body of the
if
Local and Imported Type Declarations Now Conflict
Due to a bug, the following construct was previously allowed in TypeScript:
// ./someOtherModule.ts
interface SomeType {
y: string;
}
// ./myModule.ts
import { SomeType } from "./someOtherModule";
export interface SomeType {
x: number;
}
function fn(arg: SomeType) {
console.log(arg.x); // Error! 'x' doesn't exist on 'SomeType'
}
Here, SomeType
appears to originate in both the import
declaration and the local interface
declaration.Perhaps surprisingly, inside the module, SomeType
refers exclusively to the import
ed definition, and the local declaration SomeType
is only usable when imported from another file.This is very confusing and our review of the very small number of cases of code like this in the wild showed that developers usually thought something different was happening.
In TypeScript 3.7, this is now correctly identified as a duplicate identifier error.The correct fix depends on the original intent of the author and should be addressed on a case-by-case basis.Usually, the naming conflict is unintentional and the best fix is to rename the imported type.If the intent was to augment the imported type, a proper module augmentation should be written instead.
3.7 API Changes
To enable the recursive type alias patterns described above, the typeArguments
property has been removed from the TypeReference
interface. Users should instead use the getTypeArguments
function on TypeChecker
instances.