question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google feedback on TS 4.7-beta

See original GitHub issue

This GitHub issue contains feedback on the TS 4.7-beta release from the team that is responsible for keeping Google’s internal software working with the latest version of TypeScript.

Executive summary

  • Some changes to our TypeScript code are required to make it compile with TS 4.7.
  • Detail sections below explain the changes to our code we expect to make to unblock the upgrade.

Impact summary

Change description Announced Libraries affected
Type Parameter No Longer Assignable to {} in strictNullChecks yes 0.24%
lib/d.ts changes yes 0.022%
TS2774 & TS2801 now fire for secondary conditions in if statements no 0.017%
TS2731 now fires for keyof T no 0.008%
Unclassified - 0.014%

The Announced column indicates whether we were able to connect the observed change with a section in the TS4.7-beta announcement.

The following sections give more detailed explanations of the changes listed above.

Changes which were announced

Type Parameter No Longer Assignable to {} in strictNullChecks

We see type errors similar to the ones mentioned in the release announcement.

We’re looking into adding extends object to generic type parameters where possible and casts to any to silence the error everywhere else.

lib/d.ts changes

We support the typing improvements. Generally it’s clear what’s changing.

We observed the following breakdown within this category:

  • fetch now also accepts URL in addition to RequestInfo for the first parameter

  • AbortSignal has additional members reason and throwIfAborted

  • ImageData has additional member colorSpace

  • HTMLVideoElement has additional members requestVideoFrameCallback and cancelVideoFrameCallback

  • Object.assign now rejects null/undefined for the first parameter

  • Object.freeze has an additional overload, which causes some type errors like:

    interface Data { prop: Array<'a'|'b'> }
    export const DATA: Data = Object.freeze({prop: ['a']});
    //           ^^^^ Type 'Readonly<{ prop: string[]; }>' is not assignable to type 'Data'.
    

We expect to add casts to any to silence the error and apply proper fixes over time.

Changes which were not announced

TS2774 & TS2801 now fire for secondary conditions in if statements

This wasn’t specifically mentioned in the release announcement, but looks like a decent improvement. Example:

declare let flag: boolean;
declare function foo(): void;
declare function bar(): Promise<void>;
if (flag && foo) foo();
//          ^^^ This condition will always return true since this function is always defined. Did you mean to call it instead?(2774)
if (flag && bar()) {}
//          ^^^^^ This condition will always return true since this 'Promise<void>' is always defined.(2801)

We expect to add casts to any to silence the error and apply proper fixes over time.

TS2731 now fires for keyof T

This wasn’t specifically mentioned in the release announcement, but looks like a decent improvement. Example:

function foo<T>(key: keyof T) {
  console.log(`Key: "${key}"`);
  //                   ^^^ Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'.(2731)
}

We expect to add casts to any to silence the error and apply proper fixes over time.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:12
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
DanielRosenwassercommented, Apr 29, 2022

It would be great to have this diagnostic in more situations.

So for the example that you gave

function extract<T>(obj: {}, other: Partial<T>) {
  (obj as T);
// ^^^^^^^^
// Conversion of type '{}' to type 'T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
//     'T' could be instantiated with an arbitrary type which could be unrelated to '{}'.(2352)
}

@weswigham’s PR at https://github.com/microsoft/TypeScript/pull/48861 should allow casting between {} and T.

1reaction
frigus02commented, Apr 27, 2022

That being said, I thought fetch() always accepted an URL? I’ve never passed anything but a string to it…

You’re right that string was always possible. It’s now also possible to pass e.g. new URL(...). fetch changed from accepting RequestInfo to RequestInfo | URL. Where type RequestInfo = Request | string;.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Microsoft TypeScript 4.7 Beta now available - Techzine Europe
In TypeScript 4.5, Microsoft added nightly-only support for ESM in Node.js to get some feedback from users and let library authors ready ...
Read more >
What's New in TypeScript 4.7. What are the Latest Features of…
But it was nightly-only support to get user feedback. However, TypeScript 4.7 update has introduced 2 new compiler options named node12 and ...
Read more >
Oleksandr T. (@tarasiuk_o) / Twitter
We need your feedback on our new features, speed-ups, file-watching changes, and more! Read up on what's coming in TS 4.9!
Read more >
Announcing TypeScript 4.7 Beta : r/programming - Reddit
Thank you to all the TS devs who have brought us incredible features update-after-update. I know I've been asking for this for a...
Read more >
TypeScript 4.7 beta now available - SD Times
Microsoft announced the launch of the TypeScript 4.7 beta which ... in Node.js to get some feedback from users and let library authors...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found