microsoft/TypeScript

Inconsistencies in assignability rules around top-level-like signatures

Opened this issue ยท 2 comments

๐Ÿ”Ž Search Terms

assignability any never signature

๐Ÿ•— Version & Regression Information

  • This is the behavior in every version I tried

โฏ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.0-dev.20251030#code/PTAEGcHsFcCcGMCmoCG5wEsDmA7FAjAG2QBdJQSALUlWLREgKHkh3BItvpIEYAuUAAoAdKK7gBKHAE8AlKAC8APlQzFQ0cPECciAG6JY85aADkAM0iRTjRiAgoAtsihwkAGlD5oHElwagOJAA7qCUaKAAVBgAJog4JBjwKISRoLAMcDgU0gAOyBFULjAIBTgxqISEoJDmqBDQMXHZGBzmKBiE4Mys7Jx0DABMAiJidBKqcooqFlam6qNa4zr6hsYzlta29piOnbSgGOjQiJ5+Axzh4BTUDs7pmbDZERjZAAbn3DxvQlJT3r5KEcKBh7vhIFQICUkKoKp8AuEDFFos1EslUmlEAAPEiwFCgYgoGKvLCgXK0JwMQyww5tDpdRA9Ni+fwkADMIy4AmgOAA1kFgjhPJptJN1pMFlzQDz+SEhaARctAqsjNMzJsbHYwLt9rBDsdTv1uGFCrdwJSHiQsqhrq9QB9Wd9fjJ5ACbsDEmCIZQoW4ynDWSakZEUfE0SkQ-aqEcfuS8c4SNSpBVWqB2p1wIyWMyjQwACwjaMTGUC+WKrATP7iv7qcw8+CJVhCIvcvml4VjCsrAyqgDelutACJNoOANygAC+o8YQA

๐Ÿ’ป Code

// source assignable to the target
const target1: (...args: any) => any = (...args: never) => 'foo'

// same source, but target now has *identical* return type as the source and all of a sudden it fails
const target2: (...args: any) => 'foo' = (...args: never) => 'foo'

// similar issue, target has the same return as in `target1` (any) but this time both source and target have **identical** extra leading parameter and it fails
const target3: (arg: unknown, ...args: any) => any = (arg: unknown, ...args: never) => 'foo'

// similar issue, target has the same return as in `target1` (any) but this time both source and target have **identical** `this` parameter and it fails
const target4: (this: unknown, ...args: any) => any = function (this: unknown, ...args: never) { return "foo"; };

๐Ÿ™ Actual behavior

Assignability rules behave weirdly/inconsistently in those simple examples

๐Ÿ™‚ Expected behavior

I'd expect more consistent results

Additional information about the issue

relates to #55667 - the fact examples 2-4 error is the reason why that issue exists

๐Ÿค– Thank you for your issue! I've done some analysis to help get you started. This response is automatically generated; feel free to ๐Ÿ‘ or ๐Ÿ‘Ž this comment according to its usefulness.

Similar Issues

Here are the most similar issues I found

If your issue is a duplicate of one of these, feel free to close this issue. Otherwise, no action is needed.

We can look at what "fixing" this would do. It's probably best to approach this with both a theoretical (here's what the rules should be) and empirical approach (here's what DT and RWC turn up). I don't have high hopes on this, though - people often do need a "really, just any call signature, I do not care" type that isn't needlessly invariant.