`ThisType` should use the `intrinsic` keyword
See original GitHub issueSuggestion
🔍 Search Terms
thistype intrinsic
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn’t be a breaking change in existing TypeScript/JavaScript code
- This wouldn’t change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript’s Design Goals.
⭐ Suggestion
ThisType
is quite confusing in that it appears to do nothing when you go to its definition:
interface ThisType<T> { }
but it actually has secret intrinsic functionality? so imo it should use the intrinsic
keyword:
type ThisType<T> = intrinsic
or better yet, why not implement it in the language?
type ThisType<OldThis, NewThis> = {
[K in keyof OldThis]: OldThis[K] extends (...args: never[]) => unknown
? (this: NewThis, ...args: Parameters<OldThis[K]>) => ReturnType<OldThis[K]>
: OldThis[K]
}
(though that would probably break existing code)
motivation
it’s misleading in a language when a symbol has a “fake” implementation you can look at, but its behavior is actually defined intrinsically somewhere else. for example, the NoReturn
type in python:
NoReturn = Union[None]
this is as non-sensical as its typescript equivalent:
type never = undefined
Union[None]
has nothing to do with NoReturn
. its behavior is actually intrinsically defined in type checkers such as mypy. if never
had a fake definition like this, it would be extremely confusing and it would blur the lines between what’s intrinsic and what isn’t.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:6 (3 by maintainers)
Top GitHub Comments
Because python’s typing is cringe, not based. And this particular definition looks like something straight outta python
I guess
intrinsic
tells users there is magic within, at least it’s not a empty interface (which isany
).It’s just a very small thing that can but not must be done.