Optional Chaining

Playground

Optional chaining is issue #16 on our issue tracker. For context, there have been over 23,000 issues on the TypeScript issue tracker since then.

At its core, optional chaining lets us write code where TypeScript can immediately stop running some expressions if we run into a null or undefined.The star of the show in optional chaining is the new ?. operator for optional property accesses.When we write code like

  1. let x = foo?.bar.baz();

this is a way of saying that when foo is defined, foo.bar.baz() will be computed; but when foo is null or undefined, stop what we’re doing and just return undefined.”

More plainly, that code snippet is the same as writing the following.

  1. let x = (foo === null || foo === undefined) ?
  2. undefined :
  3. foo.bar.baz();

Note that if bar is null or undefined, our code will still hit an error accessing baz.Likewise, if baz is null or undefined, we’ll hit an error at the call site.?. only checks for whether the value on the left of it is null or undefined - not any of the subsequent properties.

You might find yourself using ?. to replace a lot of code that performs repetitive nullish checks using the && operator.

  1. // Before
  2. if (foo && foo.bar && foo.bar.baz) {
  3. // ...
  4. }
  5. // After-ish
  6. if (foo?.bar?.baz) {
  7. // ...
  8. }

Keep in mind that ?. acts differently than those && operations since && will act specially on “falsy” values (e.g. the empty string, 0, NaN, and, well, false), but this is an intentional feature of the construct.It doesn’t short-circuit on valid data like 0 or empty strings.

Optional chaining also includes two other operations.First there’s the optional element access which acts similarly to optional property accesses, but allows us to access non-identifier properties (e.g. arbitrary strings, numbers, and symbols):

  1. /**
  2. * Get the first element of the array if we have an array.
  3. * Otherwise return undefined.
  4. */
  5. function tryGetFirstElement<T>(arr?: T[]) {
  6. return arr?.[0];
  7. // equivalent to
  8. // return (arr === null || arr === undefined) ?
  9. // undefined :
  10. // arr[0];
  11. }

There’s also optional call, which allows us to conditionally call expressions if they’re not null or undefined.

  1. async function makeRequest(url: string, log?: (msg: string) => void) {
  2. log?.(`Request started at ${new Date().toISOString()}`);
  3. // roughly equivalent to
  4. // if (log != null) {
  5. // log(`Request started at ${new Date().toISOString()}`);
  6. // }
  7. const result = (await fetch(url)).json();
  8. log?.(`Request finished at at ${new Date().toISOString()}`);
  9. return result;
  10. }

The “short-circuiting” behavior that optional chains have is limited property accesses, calls, element accesses - it doesn’t expand any further out from these expressions.In other words,

  1. let result = foo?.bar / someComputation()

doesn’t stop the division or someComputation() call from occurring.It’s equivalent to

  1. let temp = (foo === null || foo === undefined) ?
  2. undefined :
  3. foo.bar;
  4. let result = temp / someComputation();

That might result in dividing undefined, which is why in strictNullChecks, the following is an error.

  1. function barPercentage(foo?: { bar: number }) {
  2. return foo?.bar / 100;
  3. // ~~~~~~~~
  4. // Error: Object is possibly undefined.
  5. }

More more details, you can read up on the proposal and view the original pull request.

Nullish Coalescing

Playground

The nullish coalescing operator is another upcoming ECMAScript feature that goes hand-in-hand with optional chaining, and which our team has been involved with championing in TC39.

You can think of this feature - the ?? operator - as a way to “fall back” to a default value when dealing with null or undefined.When we write code like

  1. let x = foo ?? bar();

this is a new way to say that the value foo will be used when it’s “present”;but when it’s null or undefined, calculate bar() in its place.

Again, the above code is equivalent to the following.

  1. let x = (foo !== null && foo !== undefined) ?
  2. foo :
  3. bar();

The ?? operator can replace uses of || when trying to use a default value.For example, the following code snippet tries to fetch the volume that was last saved in localStorage (if it ever was);however, it has a bug because it uses ||.

  1. function initializeAudio() {
  2. let volume = localStorage.volume || 0.5
  3. // ...
  4. }

When localStorage.volume is set to 0, the page will set the volume to 0.5 which is unintended.?? avoids some unintended behavior from 0, NaN and "" being treated as falsy values.

We owe a large thanks to community members Wenlu Wang and Titian Cernicova Dragomir for implementing this feature!For more details, check out their pull request and the nullish coalescing proposal repository.

Assertion Functions

Playground

There’s a specific set of functions that throw an error if something unexpected happened.They’re called “assertion” functions.As an example, Node.js has a dedicated function for this called assert.

  1. assert(someValue === 42);

In this example if someValue isn’t equal to 42, then assert will throw an AssertionError.

Assertions in JavaScript are often used to guard against improper types being passed in.For example,

  1. function multiply(x, y) {
  2. assert(typeof x === "number");
  3. assert(typeof y === "number");
  4. return x * y;
  5. }

Unfortunately in TypeScript these checks could never be properly encoded.For loosely-typed code this meant TypeScript was checking less, and for slightly conservative code it often forced users to use type assertions.

  1. function yell(str) {
  2. assert(typeof str === "string");
  3. return str.toUppercase();
  4. // Oops! We misspelled 'toUpperCase'.
  5. // Would be great if TypeScript still caught this!
  6. }

The alternative was to instead rewrite the code so that the language could analyze it, but this isn’t convenient.

  1. function yell(str) {
  2. if (typeof str !== "string") {
  3. throw new TypeError("str should have been a string.")
  4. }
  5. // Error caught!
  6. return str.toUppercase();
  7. }

Ultimately the goal of TypeScript is to type existing JavaScript constructs in the least disruptive way.For that reason, TypeScript 3.7 introduces a new concept called “assertion signatures” which model these assertion functions.

The first type of assertion signature models the way that Node’s assert function works.It ensures that whatever condition is being checked must be true for the remainder of the containing scope.

  1. function assert(condition: any, msg?: string): asserts condition {
  2. if (!condition) {
  3. throw new AssertionError(msg)
  4. }
  5. }

asserts condition says that whatever gets passed into the condition parameter must be true if the assert returns (because otherwise it would throw an error).That means that for the rest of the scope, that condition must be truthy.As an example, using this assertion function means we do catch our original yell example.

  1. function yell(str) {
  2. assert(typeof str === "string");
  3. return str.toUppercase();
  4. // ~~~~~~~~~~~
  5. // error: Property 'toUppercase' does not exist on type 'string'.
  6. // Did you mean 'toUpperCase'?
  7. }
  8. function assert(condition: any, msg?: string): asserts condition {
  9. if (!condition) {
  10. throw new AssertionError(msg)
  11. }
  12. }

The other type of assertion signature doesn’t check for a condition, but instead tells TypeScript that a specific variable or property has a different type.

  1. function assertIsString(val: any): asserts val is string {
  2. if (typeof val !== "string") {
  3. throw new AssertionError("Not a string!");
  4. }
  5. }

Here asserts val is string ensures that after any call to assertIsString, any variable passed in will be known to be a string.

  1. function yell(str: any) {
  2. assertIsString(str);
  3. // Now TypeScript knows that 'str' is a 'string'.
  4. return str.toUppercase();
  5. // ~~~~~~~~~~~
  6. // error: Property 'toUppercase' does not exist on type 'string'.
  7. // Did you mean 'toUpperCase'?
  8. }

These assertion signatures are very similar to writing type predicate signatures:

  1. function isString(val: any): val is string {
  2. return typeof val === "string";
  3. }
  4. function yell(str: any) {
  5. if (isString(str)) {
  6. return str.toUpperCase();
  7. }
  8. throw "Oops!";
  9. }

And just like type predicate signatures, these assertion signatures are incredibly expressive.We can express some fairly sophisticated ideas with these.

  1. function assertIsDefined<T>(val: T): asserts val is NonNullable<T> {
  2. if (val === undefined || val === null) {
  3. throw new AssertionError(
  4. `Expected 'val' to be defined, but received ${val}`
  5. );
  6. }
  7. }

To read up more about assertion signatures, check out the original pull request.

Better Support for never-Returning Functions

As part of the work for assertion signatures, TypeScript needed to encode more about where and which functions were being called.This gave us the opportunity to expand support for another class of functions: functions that return never.

The intent of any function that returns never is that it never returns.It indicates that an exception was thrown, a halting error condition occurred, or that the program exited.For example, process.exit(…) in @types/node is specified to return never.

In order to ensure that a function never potentially returned undefined or effectively returned from all code paths, TypeScript needed some syntactic signal - either a return or throw at the end of a function.So users found themselves return-ing their failure functions.

  1. function dispatch(x: string | number): SomeType {
  2. if (typeof x === "string") {
  3. return doThingWithString(x);
  4. }
  5. else if (typeof x === "number") {
  6. return doThingWithNumber(x);
  7. }
  8. return process.exit(1);
  9. }

Now when these never-returning functions are called, TypeScript recognizes that they affect the control flow graph and accounts for them.

  1. function dispatch(x: string | number): SomeType {
  2. if (typeof x === "string") {
  3. return doThingWithString(x);
  4. }
  5. else if (typeof x === "number") {
  6. return doThingWithNumber(x);
  7. }
  8. process.exit(1);
  9. }

As with assertion functions, you can read up more at the same pull request.

(More) Recursive Type Aliases

Playground

Type aliases have always had a limitation in how they could be “recursively” referenced.The reason is that any use of a type alias needs to be able to substitute itself with whatever it aliases.In some cases, that’s not possible, so the compiler rejects certain recursive aliases like the following:

  1. type Foo = Foo;

This is a reasonable restriction because any use of Foo would need to be replaced with Foo which would need to be replaced with Foo which would need to be replaced with Foo which… well, hopefully you get the idea!In the end, there isn’t a type that makes sense in place of Foo.

This is fairly consistent with how other languages treat type aliases, but it does give rise to some slightly surprising scenarios for how users leverage the feature.For example, in TypeScript 3.6 and prior, the following causes an error.

  1. type ValueOrArray<T> = T | Array<ValueOrArray<T>>;
  2. // ~~~~~~~~~~~~
  3. // error: Type alias 'ValueOrArray' circularly references itself.

This is strange because there is technically nothing wrong with any use users could always write what was effectively the same code by introducing an interface.

  1. type ValueOrArray<T> = T | ArrayOfValueOrArray<T>;
  2. interface ArrayOfValueOrArray<T> extends Array<ValueOrArray<T>> {}

Because interfaces (and other object types) introduce a level of indirection and their full structure doesn’t need to be eagerly built out, TypeScript has no problem working with this structure.

But workaround of introducing the interface wasn’t intuitive for users.And in principle there really wasn’t anything wrong with the original version of ValueOrArray that used Array directly.If the compiler was a little bit “lazier” and only calculated the type arguments to Array when necessary, then TypeScript could express these correctly.

That’s exactly what TypeScript 3.7 introduces.At the “top level” of a type alias, TypeScript will defer resolving type arguments to permit these patterns.

This means that code like the following that was trying to represent JSON…

  1. type Json =
  2. | string
  3. | number
  4. | boolean
  5. | null
  6. | JsonObject
  7. | JsonArray;
  8. interface JsonObject {
  9. [property: string]: Json;
  10. }
  11. interface JsonArray extends Array<Json> {}

can finally be rewritten without helper interfaces.

  1. type Json =
  2. | string
  3. | number
  4. | boolean
  5. | null
  6. | { [property: string]: Json }
  7. | Json[];

This new relaxation also lets us recursively reference type aliases in tuples as well.The following code which used to error is now valid TypeScript code.

  1. type VirtualNode =
  2. | string
  3. | [string, { [key: string]: any }, ...VirtualNode[]];
  4. const myNode: VirtualNode =
  5. ["div", { id: "parent" },
  6. ["div", { id: "first-child" }, "I'm the first child"],
  7. ["div", { id: "second-child" }, "I'm the second child"]
  8. ];

For more information, you can read up on the original pull request.

—declaration and —allowJs

The —declaration flag in TypeScript allows us to generate .d.ts files (declaration files) from TypeScript source files (i.e. .ts and .tsx files).These .d.ts files are important for a couple of reasons.

First of all, they’re important because they allow TypeScript to type-check against other projects without re-checking the original source code.They’re also important because they allow TypeScript to interoperate with existing JavaScript libraries that weren’t built with TypeScript in mind.Finally, a benefit that is often underappreciated: both TypeScript and JavaScript users can benefit from these files when using editors powered by TypeScript to get things like better auto-completion.

Unfortunately, —declaration didn’t work with the —allowJs flag which allows mixing TypeScript and JavaScript input files.This was a frustrating limitation because it meant users couldn’t use the —declaration flag when migrating codebases, even if they were JSDoc-annotated.TypeScript 3.7 changes that, and allows the two options to be used together!

The most impactful outcome of this feature might a bit subtle: with TypeScript 3.7, users can write libraries in JSDoc annotated JavaScript and support TypeScript users.

The way that this works is that when using allowJs, TypeScript has some best-effort analyses to understand common JavaScript patterns; however, the way that some patterns are expressed in JavaScript don’t necessarily look like their equivalents in TypeScript.When declaration emit is turned on, TypeScript figures out the best way to transform JSDoc comments and CommonJS exports into valid type declarations and the like in the output .d.ts files.

As an example, the following code snippet

  1. const assert = require("assert")
  2. module.exports.blurImage = blurImage;
  3. /**
  4. * Produces a blurred image from an input buffer.
  5. *
  6. * @param input {Uint8Array}
  7. * @param width {number}
  8. * @param height {number}
  9. */
  10. function blurImage(input, width, height) {
  11. const numPixels = width * height * 4;
  12. assert(input.length === numPixels);
  13. const result = new Uint8Array(numPixels);
  14. // TODO
  15. return result;
  16. }

Will produce a .d.ts file like

  1. /**
  2. * Produces a blurred image from an input buffer.
  3. *
  4. * @param input {Uint8Array}
  5. * @param width {number}
  6. * @param height {number}
  7. */
  8. export function blurImage(input: Uint8Array, width: number, height: number): Uint8Array;

This can go beyond basic functions with @param tags too, where the following example:

  1. /**
  2. * @callback Job
  3. * @returns {void}
  4. */
  5. /** Queues work */
  6. export class Worker {
  7. constructor(maxDepth = 10) {
  8. this.started = false;
  9. this.depthLimit = maxDepth;
  10. /**
  11. * NOTE: queued jobs may add more items to queue
  12. * @type {Job[]}
  13. */
  14. this.queue = [];
  15. }
  16. /**
  17. * Adds a work item to the queue
  18. * @param {Job} work
  19. */
  20. push(work) {
  21. if (this.queue.length + 1 > this.depthLimit) throw new Error("Queue full!");
  22. this.queue.push(work);
  23. }
  24. /**
  25. * Starts the queue if it has not yet started
  26. */
  27. start() {
  28. if (this.started) return false;
  29. this.started = true;
  30. while (this.queue.length) {
  31. /** @type {Job} */(this.queue.shift())();
  32. }
  33. return true;
  34. }
  35. }

will be transformed into the following .d.ts file:

  1. /**
  2. * @callback Job
  3. * @returns {void}
  4. */
  5. /** Queues work */
  6. export class Worker {
  7. constructor(maxDepth?: number);
  8. started: boolean;
  9. depthLimit: number;
  10. /**
  11. * NOTE: queued jobs may add more items to queue
  12. * @type {Job[]}
  13. */
  14. queue: Job[];
  15. /**
  16. * Adds a work item to the queue
  17. * @param {Job} work
  18. */
  19. push(work: Job): void;
  20. /**
  21. * Starts the queue if it has not yet started
  22. */
  23. start(): boolean;
  24. }
  25. export type Job = () => void;

Note that when using these flags together, TypeScript doesn’t necessarily have to downlevel .js files.If you simply want TypeScript to create .d.ts files, you can use the —emitDeclarationOnly compiler option.

For more details, you can check out the original pull request.

The useDefineForClassFields Flag and The declare Property Modifier

Back when TypeScript implemented public class fields, we assumed to the best of our abilities that the following code

  1. class C {
  2. foo = 100;
  3. bar: string;
  4. }

would be equivalent to a similar assignment within a constructor body.

  1. class C {
  2. constructor() {
  3. this.foo = 100;
  4. }
  5. }

Unfortunately, while this seemed to be the direction that the proposal moved towards in its earlier days, there is an extremely strong chance that public class fields will be standardized differently.Instead, the original code sample might need to de-sugar to something closer to the following:

  1. class C {
  2. constructor() {
  3. Object.defineProperty(this, "foo", {
  4. enumerable: true,
  5. configurable: true,
  6. writable: true,
  7. value: 100
  8. });
  9. Object.defineProperty(this, "bar", {
  10. enumerable: true,
  11. configurable: true,
  12. writable: true,
  13. value: void 0
  14. });
  15. }
  16. }

While TypeScript 3.7 isn’t changing any existing emit by default, we’ve been rolling out changes incrementally to help users mitigate potential future breakage.We’ve provided a new flag called useDefineForClassFields to enable this emit mode with some new checking logic.

The two biggest changes are the following:

  • Declarations are initialized with Object.defineProperty.
  • Declarations are always initialized to undefined, even if they have no initializer.

This can cause quite a bit of fallout for existing code that use inheritance. First of all, set accessors from base classes won’t get triggered - they’ll be completely overwritten.

  1. class Base {
  2. set data(value: string) {
  3. console.log("data changed to " + value);
  4. }
  5. }
  6. class Derived extends Base {
  7. // No longer triggers a 'console.log'
  8. // when using 'useDefineForClassFields'.
  9. data = 10;
  10. }

Secondly, using class fields to specialize properties from base classes also won’t work.

  1. interface Animal { animalStuff: any }
  2. interface Dog extends Animal { dogStuff: any }
  3. class AnimalHouse {
  4. resident: Animal;
  5. constructor(animal: Animal) {
  6. this.resident = animal;
  7. }
  8. }
  9. class DogHouse extends AnimalHouse {
  10. // Initializes 'resident' to 'undefined'
  11. // after the call to 'super()' when
  12. // using 'useDefineForClassFields'!
  13. resident: Dog;
  14. constructor(dog: Dog) {
  15. super(dog);
  16. }
  17. }

What these two boil down to is that mixing properties with accessors is going to cause issues, and so will re-declaring properties with no initializers.

To detect the issue around accessors, TypeScript 3.7 will now emit get/set accessors in .d.ts files so that in TypeScript can check for overridden accessors.

Code that’s impacted by the class fields change can get around the issue by converting field initializers to assignments in constructor bodies.

  1. class Base {
  2. set data(value: string) {
  3. console.log("data changed to " + value);
  4. }
  5. }
  6. class Derived extends Base {
  7. constructor() {
  8. data = 10;
  9. }
  10. }

To help mitigate the second issue, you can either add an explicit initializer or add a declare modifier to indicate that a property should have no emit.

  1. interface Animal { animalStuff: any }
  2. interface Dog extends Animal { dogStuff: any }
  3. class AnimalHouse {
  4. resident: Animal;
  5. constructor(animal: Animal) {
  6. this.resident = animal;
  7. }
  8. }
  9. class DogHouse extends AnimalHouse {
  10. declare resident: Dog;
  11. // ^^^^^^^
  12. // 'resident' now has a 'declare' modifier,
  13. // and won't produce any output code.
  14. constructor(dog: Dog) {
  15. super(dog);
  16. }
  17. }

Currently useDefineForClassFields is only available when targeting ES5 and upwards, since Object.defineProperty doesn’t exist in ES3.To achieve similar checking for issues, you can create a seperate project that targets ES5 and uses —noEmit to avoid a full build.

For more information, you can take a look at the original pull request for these changes.

We strongly encourage users to try the useDefineForClassFields flag and report back on our issue tracker or in the comments below.This includes feedback on difficulty of adopting the flag so we can understand how we can make migration easier.

Build-Free Editing with Project References

TypeScript’s project references provide us with an easy way to break codebases up to give us faster compiles.Unfortunately, editing a project whose dependencies hadn’t been built (or whose output was out of date) meant that the editing experience wouldn’t work well.

In TypeScript 3.7, when opening a project with dependencies, TypeScript will automatically use the source .ts/.tsx files instead.This means projects using project references will now see an improved editing experience where semantic operations are up-to-date and “just work”.You can disable this behavior with the compiler option disableSourceOfProjectReferenceRedirect which may be appropriate when working in very large projects where this change may impact editing performance.

You can read up more about this change by reading up on its pull request.

Uncalled Function Checks

A common and dangerous error is to forget to invoke a function, especially if the function has zero arguments or is named in a way that implies it might be a property rather than a function.

  1. interface User {
  2. isAdministrator(): boolean;
  3. notify(): void;
  4. doNotDisturb?(): boolean;
  5. }
  6. // later...
  7. // Broken code, do not use!
  8. function doAdminThing(user: User) {
  9. // oops!
  10. if (user.isAdministrator) {
  11. sudo();
  12. editTheConfiguration();
  13. }
  14. else {
  15. throw new AccessDeniedError("User is not an admin");
  16. }
  17. }

Here, we forgot to call isAdministrator, and the code incorrectly allows non-adminstrator users to edit the configuration!

In TypeScript 3.7, this is identified as a likely error:

  1. function doAdminThing(user: User) {
  2. if (user.isAdministrator) {
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. // error! This condition will always return true since the function is always defined.
  5. // Did you mean to call it instead?

This check is a breaking change, but for that reason the checks are very conservative.This error is only issued in if conditions, and it is not issued on optional properties, if strictNullChecks is off, or if the function is later called within the body of the if:

  1. interface User {
  2. isAdministrator(): boolean;
  3. notify(): void;
  4. doNotDisturb?(): boolean;
  5. }
  6. function issueNotification(user: User) {
  7. if (user.doNotDisturb) {
  8. // OK, property is optional
  9. }
  10. if (user.notify) {
  11. // OK, called the function
  12. user.notify();
  13. }
  14. }

If you intended to test the function without calling it, you can correct the definition of it to include undefined/null, or use !! to write something like if (!!user.isAdministrator) to indicate that the coercion is intentional.

We owe a big thanks to GitHub user @jwbay who took the initiative to create a proof-of-concept and iterated to provide us with with the current version.

// @ts-nocheck in TypeScript Files

TypeScript 3.7 allows us to add // @ts-nocheck comments to the top of TypeScript files to disable semantic checks.Historically this comment was only respected in JavaScript source files in the presence of checkJs, but we’ve expanded support to TypeScript files to make migrations easier for all users.

Semicolon Formatter Option

TypeScript’s built-in formatter now supports semicolon insertion and removal at locations where a trailing semicolon is optional due to JavaScript’s automatic semicolon insertion (ASI) rules. The setting is available now in Visual Studio Code Insiders, and will be available in Visual Studio 16.4 Preview 2 in the Tools Options menu.

New semicolon formatter option in VS Code

Choosing a value of “insert” or “remove” also affects the format of auto-imports, extracted types, and other generated code provided by TypeScript services. Leaving the setting on its default value of “ignore” makes generated code match the semicolon preference detected in the current file.

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 initializer

To 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:

  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.