Repository: TypeScript
Issue: Google feedback on TS 5.5-beta
Labels: Discussion

### Acknowledgement

- [X] I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

### Comment

This GitHub issue contains feedback on the TS 5.5-beta release from the team
that is responsible for keeping Google's internal software working with the
latest version of TypeScript.

## Executive summary

*   We do not expect to have significant difficulty in upgrading Google to TS
    5.5.
*   Some changes to our TypeScript code are required to make it compile with TS
    5.5.
*   Detail sections below explain the changes to our code we expect to make to
    unblock the upgrade.

## Impact summary

Change description                 | Announced | Libraries affected
---------------------------------- | --------: | -----------------:
Inferred type predicates           | yes       | 0.018%
Template literal types + enums     | no        | 0.011%
Regular expression syntax checking | yes       | 0.007%
Const indexed accesses             | yes       | 0.003%
lib/d.ts changes                   | yes       | 0.003%
IsolatedModules string             | no        | 0.003%

The **Announced** column indicates whether we were able to connect the observed
change with a section in the
[TS5.5-beta announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-5-4-beta/).

The following sections give more detailed explanations of the changes listed
above.

## Changes which were announced

### lib/d.ts Changes

We support the typing improvements. Generally it's clear what's changing and the
changes seems minimal this time.

For the TSC changes, we expect to fix our codebase to comply to the new API and
for other typing changes, we expect to `// @ts-ignore` to silence the errors.

### Inferred type predicates

https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/#inferred-type-predicates

We support this change. We expect to `// @ts-ignore` to silence new errors.

The only downside is a few targets broken by unwanted narrowing, but we plan to
either suppress with `@ts-ignore` or add an explicit type declaration.

Here's an example of the kind of working code that broke:

```ts
declare function getFlagsList(): Flag[];
declare function shouldAddA(): boolean;
enum Flag {
    A,
    B,
    C
}
// Type changes between 5.4.2 and 5.5-beta.
const flags = getFlagsList()
  .filter((f) => f !== Flag.A);
if (shouldAddA()) {
    // Error in 5.5-beta:
    // Argument of type 'Flag.A' is not assignable to parameter of type
    // 'Flag.B | Flag.C'.
    flags.push(Flag.A);
}
```

### Regular expression syntax checking

https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/#regular-expression-syntax-checking

We support this change. Most breakages were due to code using newer syntax
features not transpiled down to older browsers, and we expect to `@ts-ignore`
the breakages.

### Control flow narrowing for const indexed accesses

https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/#control-flow-narrowing-for-constant-indexed-accesses

We support this change. We expect to `// @ts-ignore` to silence new errors.

## Other changes

### Template literal type + enum

We noticed a small change in how templatized template literal types interact
with string enums.

TS 5.4.2 :
[playground link](https://www.typescriptlang.org/play/?isolatedModules=true&ts=5.4.5#code/FAegVGAEBKCmAOAnWBnWA7ALiymAWskGArgLaQBuAhgDbGED2ikVkKmiAlugOaQDuiKvHiwAJpVr1IDAGa4CRdGQB0kMCGCwAHvCaZcAT1GQAostLiAyh248APABUi2zBjE52XXgD5IAXkgAAwASAG9HAF8ggG5gLQtIADEGBkgw4EhIAA0AyABybXyAGkzIAE08-MN84EjgIKDgAGMGdHZIbQAuMwtrW157FIY-QOGVbJjIEBABJgBrFGLIdDTYREQmFraOwx7zMn7vB2HRgpqpmbnERchuSEcrSABWFQAWFWfIACNiA1WDI8Xp8VAAGAC031gmCowCAA)

TS 5.5 :
[playground link](https://www.typescriptlang.org/play/?isolatedModules=true&ts=5.5.0-beta#code/FAegVGAEBKCmAOAnWBnWA7ALiymAWskGArgLaQBuAhgDbGED2ikVkKmiAlugOaQDuiKvHiwAJpVr1IDAGa4CRdGQB0kMCGCwAHvCaZcAT1GQAostLiAyh248APABUi2zBjE52XXgD5IAXkgAAwASAG9HAF8ggG5gLQtIADEGBkgw4EhIAA0AyABybXyAGkzIAE08-MN84EjgIKDgAGMGdHZIbQAuMwtrW157FIY-QOGVbJjIEBABJgBrFGLIdDTYREQmFraOwx7zMn7vB2HRgpqpmbnERchuSEcrSABWFQAWFWfIACNiA1WDI8Xp8VAAGAC031gmCowCAA)

```ts
/** Represents the enum value or a string wrapped value of the enum. */
export type EnumedString<T extends string> = `${T}`;

enum Foo {
  X = 'x',
  Y = 'y'
}

const x: EnumedString<Foo> = Foo.X; // works, no error
const y: EnumedString<Foo> = 'y'; // works in TS 5.4.5 but not TS 5.5.0-beta
```

This is not a blocker as we can switch usages of `EnumedString<Foo>` to `${Foo}`

### IsolatedModules string

We noticed more errors like "FOO has a string type, but must have syntactically
recognizable string syntax when 'isolatedModules' is enabled." for code like
this:

```ts
import {FOO} from './other_module';

export enum E = {
    FOO,
    BAR = 'bar'
};
```

These errors seem reasonable and we will `@ts-ignore` to unblock the upgrade.

### CommonJS module emit bug

We are affected by the change in CommonJS module emit bug reported in
https://github.com/microsoft/TypeScript/issues/58473. If it's infeasible to fix
by the RC we will add a patch to our internal compiler fork.