Skip to content

Google feedback on TS 5.5-beta #58685

Open

Description

Acknowledgement

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

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:

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

TS 5.5 :
playground link

/** 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:

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
#58473. If it's infeasible to fix
by the RC we will add a patch to our internal compiler fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    DiscussionIssues which may not have code impact

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions