TypeScript 4.6 regression
See original GitHub issueBug Report
I have read the release notes and the code that is breaking for me is not mentioned in the breaking changes section.
🔎 Search Terms
None. As the code works with 4.5
🕗 Version & Regression Information
The typeof var === 'function'
call narrows the variable to function vs one of the union.
- This changed between versions
4.5
and4.6
⏯ Playground Link
Playground link with relevant code
💻 Code
type Context = Record<string, any>
class Foo<T extends Context> {
private contextAccumlator!: () => T | Promise<T>
constructor(
context: T | (() => T | Promise<T>)
) {
if (typeof context === 'function') {
this.contextAccumlator = context
}
}
}
🙁 Actual behavior
I expect this.contextAccumlator = context
to report zero errors.
🙂 Expected behavior
Instead it says
Type '(() => T | Promise<T>) | (T & Function)' is not assignable to type '() => T | Promise<T>'.
Type 'T & Function' is not assignable to type '() => T | Promise<T>'.
Type 'Context & Function' provides no match for the signature '(): T | Promise<T>'.(2322)
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Documentation - TypeScript 4.6
Control Flow Analysis for Destructured Discriminated Unions ... TypeScript is able to narrow types based on what's called a discriminant property. For example,...
Read more >Announcing TypeScript 4.5 - Microsoft Developer Blogs
If this regression blocked you from trying TypeScript 4.4, you should see comparable or better speed in --build mode compared to past versions....
Read more >Typescript version support - SonarQube - Sonar Community
The TypeScript page states that TypeScript versions must be in the range ... some performance regression with the last versions of eslint, ...
Read more >Typescript 4.5 Version Unveiled with New Improvements
On the next version of TypeScript, Rosenwasser adds, "We're already working on TypeScript 4.6!" If you are curious to hear more, ...
Read more >visual-regression-tracker/agent-codeceptjs - npm package
Learn more about @visual-regression-tracker/agent-codeceptjs: package health ... COdeceptJS (docs)[https://codecept.io/commands/#typescript-definitions].
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay! Thanks for the clarification 😃
Yes, that’s why it’s a Docs bug assigned to the blog post author