Skip to content

Bloomberg feedback on TypeScript 4.7 Beta #49071

Closed
@dragomirtitian

Description

@dragomirtitian

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

# Change Affects Release notes Packages affected Introduced in
1 Detection of weak generic types Type checking Announced 100% #48366
2 Symbol included in keyof T Type checking Not Announced 2%
3 Better always true detection Type checking Not Announced <1%
4 Comments on default exports have moved d.ts emit Not Announced 5%
5 Optional parameter does not on include undefined d.ts emit Not Announced 2% #48605
6 Changes in emitted conditional types d.ts emit Not 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:

type Spec = {
    props?: string[]
}
type Class<T extends Spec> = { s: Spec }
function cls<T>(s: T):Class<T> { return null! }

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:

function add<T>(p: keyof T) {
    return "prefix." + p;
}
function message<T>(p: keyof T) {
    return `prefix.${p}`;
}

Playground Link 4.6 / Playground Link 4.7

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

export type Context = {
    V1: { "a": string },
    V2: { "b": string },
}
function path<V extends keyof Context, K extends keyof Context[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