microsoft / microsoft/TypeScript
typeof 'function' using with Exclude<T, Function>
Open
Nobody has claimed this yet.
Bug
Domain: check: Control Flow
Domain: Conditional Types
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.2.2
Search Terms: Generic typeof
Code
function f2<T>(v: Exclude<T, Function> | (() => T)): T {
if (typeof v === 'function') {
v = v() // error!
}
return v
}
Expected behavior:
No error, type v is just (() => T).
Actual behavior:
Line 3 report an error: Type '(() => T) | (Exclude<T, Function> & Function)' has no compatible call signatures.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Playground Link and reproduce the error in f2 using TypeScript 3.2.2. Investigate how typeof 'function' narrows the union involving Exclude<T, Function>; the work is done when v is recognized as callable in that branch without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100