Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google feedback on TS 5.5-beta #58685

Open
1 task done
lauraharker opened this issue May 28, 2024 · 4 comments
Open
1 task done

Google feedback on TS 5.5-beta #58685

lauraharker opened this issue May 28, 2024 · 4 comments
Labels
Discussion Issues which may not have code impact

Comments

@lauraharker
Copy link

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.

@DanielRosenwasser DanielRosenwasser added the Discussion Issues which may not have code impact label May 28, 2024
@DanielRosenwasser
Copy link
Member

Thank you for taking the time to put this feedback together @lauraharker!

@ahejlsberg
Copy link
Member

any idea what might have changed the behavior of that template string example?

See #58687.

@jakebailey
Copy link
Member

Merged the fix for #58473.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Issues which may not have code impact
Projects
None yet
Development

No branches or pull requests

4 participants