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.

TypeScript 4.6 regression

See original GitHub issue

Bug 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 and 4.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:open
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
thetutlagecommented, Mar 5, 2022

Okay! Thanks for the clarification 😃

0reactions
RyanCavanaughcommented, Mar 5, 2022

Yes, that’s why it’s a Docs bug assigned to the blog post author

Read more comments on GitHub >

github_iconTop 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 >

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