- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.1k
 
Open
Labels
DocsThe issue relates to how you learn TypeScriptThe issue relates to how you learn TypeScript
Description
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.5and4.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)
Metadata
Metadata
Assignees
Labels
DocsThe issue relates to how you learn TypeScriptThe issue relates to how you learn TypeScript