Microsoft/TypeScript

Weak type not rejected when intersected with `ThisType`

Open

#56.995 aberto em 9 de jan. de 2024

Ver no GitHub
 (6 comments) (0 reactions) (0 assignees)TypeScript (6.726 forks)batch import
BugDomain: This-TypingHelp Wanted

Métricas do repositório

Stars
 (48.455 stars)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)

Description

🔎 Search Terms

  • function overload
  • ThisType
  • this

🕗 Version & Regression Information

  • This is a crash

⏯ Playground Link

https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgGIHt3IN4ChnJwBcyAzmFKAOa4C+uAJhAgDZxQowCuICYw6EMm4gADAAp2VEuICUyALwA+ZOPzIAZGkzqtAFQAWwUnoCeABwgAeDOiW5ZskgDd0wBo2ZsOwnnwFCIhJSMrrIAArs-HAsNpj2BPpGJhbWtvaOLm4euEHieAD0BcgAegD86sTIAOQAjNV0srk8EnKKKvm4RaUVBFV1DbSOXcUAAmCkALQQAB6WfNNQUOhQzWLibcqqhcXllSS1jU1AA

💻 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.

Guia do colaborador