question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`ThisType` should use the `intrinsic` keyword

See original GitHub issue

Suggestion

🔍 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:open
  • Created 2 years ago
  • Reactions:6
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
KotlinIslandcommented, Nov 18, 2021

Because python’s typing is cringe, not based. And this particular definition looks like something straight outta python

0reactions
yume-chancommented, Jan 25, 2022

I guess intrinsic tells users there is magic within, at least it’s not a empty interface (which is any).

It’s just a very small thing that can but not must be done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

03.31.2022 - TypeScript/The intrinsic keyword
intrinsic is the keyword that TypeScript used to let the type checker know that it needs to provide an implementation for this type...
Read more >
Intrinsic Types in TypeScript - Level Up Coding - gitconnected
As of TypeScript 4.1, there exist 4 intrinsic types : Lowercase , Uppercase , Capitalize and Uncapitalize , all of them defined using...
Read more >
Documentation - Utility Types - TypeScript
Constructs an object type whose property keys are Keys and whose property values are Type . This utility can be used to map...
Read more >
Intrinsic string types by ahejlsberg · Pull Request #40580
The new intrinsic keyword is used to indicate that the type alias references a compiler provided implementation. It is an error to specify...
Read more >
Understanding infer in TypeScript - LogRocket Blog
The infer keyword and conditional typing in TypeScript allow us to take a type and ... You will often see it being used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found