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:

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:

  1. // ./someOtherModule.ts
  2. interface SomeType {
  3. y: string;
  4. }
  5. // ./myModule.ts
  6. import { SomeType } from "./someOtherModule";
  7. export interface SomeType {
  8. x: number;
  9. }
  10. function fn(arg: SomeType) {
  11. console.log(arg.x); // Error! 'x' doesn't exist on 'SomeType'
  12. }

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 imported 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.