microsoft / microsoft/TypeScript
Weak type not rejected when intersected with `ThisType`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
- function overload
- ThisType
- this
🕗 Version & Regression Information
- This is a crash
⏯ Playground Link
💻 Code
interface Foo {
a: string
}
declare function fun0(arg: () => (
& Foo
& ThisType<Foo>
)): void
declare function fun0(arg: (
& Partial<Foo>
& ThisType<Foo>
)): void
fun0({
// ^? function fun0(arg: (Partial<Foo> & ThisType<Foo>)): void (+1 overload)
a: '1'
})
fun0(() => ({
// ^? function fun0(arg: () => (Foo & ThisType<Foo>)): void (+1 overload)
a: '1'
}))
// @ts-expect-error
fun0(() => ({
// ^? function fun0(arg: (Partial<Foo> & ThisType<Foo>)): void (+1 overload)
a: 1
}))
When I intersect ThisType with a type similar to {} and use it as a function argument, it will always resolve to this declaration.
🙁 Actual behavior
overload to function fun0(arg: (Partial<Foo> & ThisType<Foo>)): void (+1 overload)
🙂 Expected behavior
overload to function fun0(arg: () => (Partial<Foo> & ThisType<Foo>)): void (+1 overload)
Additional information about the issue
When I comment ThisType intesection, it works.
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 linked TypeScript Playground example and reproduce the overload-resolution behavior involving ThisType, Foo, and Partial. Trace the compiler's handling of intersections with ThisType and function arguments; done means the third call is rejected and the inferred overload matches the expected function type without a crash.
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
- Mostly clear
- Newbie friendliness
- 42/100