Google feedback on TS 4.7-beta
See original GitHub issueThis 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 acceptsURL
in addition toRequestInfo
for the first parameter -
AbortSignal
has additional membersreason
andthrowIfAborted
-
ImageData
has additional membercolorSpace
-
HTMLVideoElement
has additional membersrequestVideoFrameCallback
andcancelVideoFrameCallback
-
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:
- Created a year ago
- Reactions:12
- Comments:10 (3 by maintainers)
So for the example that you gave
@weswigham’s PR at https://github.com/microsoft/TypeScript/pull/48861 should allow casting between
{}
andT
.You’re right that
string
was always possible. It’s now also possible to pass e.g.new URL(...)
. fetch changed from acceptingRequestInfo
toRequestInfo | URL
. Wheretype RequestInfo = Request | string;
.