Skip to content

Bloomberg feedback on TypeScript 4.7 Beta#49071

@dragomirtitian

Description

@dragomirtitian

We are in the process of evaluating the impact of upgrading to 4.7 on our codebase. Here some preliminary findings:

#ChangeAffectsRelease notesPackages affectedIntroduced in
1Detection of weak generic typesType checkingAnnounced100%#48366
2Symbol included in keyof TType checkingNot Announced2%
3Better always true detectionType checkingNot Announced<1%
4Comments on default exports have movedd.ts emitNot Announced5%
5Optional parameter does not on include undefinedd.ts emitNot Announced2%#48605
6Changes in emitted conditional typesd.ts emitNot Announced<1%#48592

Detection of weak generic types

This was reverted by #48923

The generic weak types on constraints has caused all our packages to fail due to an error in a base package. The specific pattern that we ran into is this:

typeSpec={props?: string[]}typeClass<TextendsSpec>={s: Spec}functioncls<T>(s: T):Class<T>{returnnull!}

Playground Link 4.6 / Playground Link 4.7

This was already reverted but we are implementing fixes based on the error to ensure if this is turned on in the future we will be better prepared.

Symbol is now included in keyof T

This was the biggest source of breaking changes (post reverting weak generic type detection) breaking on the order of 2% of packages. We ran into this when concatenating or interpolating keyof T into a string:

functionadd<T>(p: keyofT){return"prefix."+p;}functionmessage<T>(p: keyofT){return`prefix.${p}`;}

Playground Link 4.6 / Playground Link 4.7

This new inclusion of symbol appears to be too eager in certain scenarios:

exporttypeContext={V1: {"a": string},V2: {"b": string},}functionpath<VextendskeyofContext,KextendskeyofContext[V]>(v: V,k: K){// v is treated as string// k is not treated as a string, even though it can only ever be "a" | "b"return`${v}.${k}`}

Playground Link 4.6 / Playground Link 4.7

Better detection of always true conditions

This caused 5 errors in 0.5% of packages, 1 of which is definitely an error (an un-awaited promise). The others are method definitions that are checked to exist, mostly in tests so they are probably intentional.

Changes in declaration emit

This version changed declaration emit in several ways that we found to be benign:

  1. Comments on default exports are now moved on the symbol that is exported not the default export statement
  2. Optional parameters no longer emit | undefined on the parameter type if it was not explicitly added (this seems like a improvement)
  3. One declaration map changed for unknown reasons
  4. Changes to how conditional types are inlined. This is due to this PR. This seems like an improvement but we are still investigating the impact on downstream consumers of these packages.

Metadata

Metadata

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