TIL: How to get a live preview of a inferred type in typescript

Hi 👋, i am @Jarvispact. Todays blog post is going to be a quick one. I am writing typescript for 3+ years already and just right now stumbled upon a really neat feature, which i want to share with you.

TIL: that you can use a special comment format to…


This content originally appeared on DEV Community and was authored by jarvispact

Hi 👋, i am @Jarvispact. Todays blog post is going to be a quick one. I am writing typescript for 3+ years already and just right now stumbled upon a really neat feature, which i want to share with you.

TIL: that you can use a special comment format to get a live preview of the inferred type without the need of hovering over a variable.

const identity = <T>(x: T) => x;
const val = identity('change-me');
//    ^?

Notice the comment in the last line. As long as the ^ character points to a variable it will render a live preview of the inferred type on the right side of the question mark.

Here is a TS Playground to play around with the feature yourself.

Thats it, i promised that it will be a short one 😉. If you are interested in a more detailled blog post about typescript, check it out: Typescript - beyond the basics.

Ok 👋


This content originally appeared on DEV Community and was authored by jarvispact


Print Share Comment Cite Upload Translate Updates
APA

jarvispact | Sciencx (2022-06-22T15:50:49+00:00) TIL: How to get a live preview of a inferred type in typescript. Retrieved from https://www.scien.cx/2022/06/22/til-how-to-get-a-live-preview-of-a-inferred-type-in-typescript/

MLA
" » TIL: How to get a live preview of a inferred type in typescript." jarvispact | Sciencx - Wednesday June 22, 2022, https://www.scien.cx/2022/06/22/til-how-to-get-a-live-preview-of-a-inferred-type-in-typescript/
HARVARD
jarvispact | Sciencx Wednesday June 22, 2022 » TIL: How to get a live preview of a inferred type in typescript., viewed ,<https://www.scien.cx/2022/06/22/til-how-to-get-a-live-preview-of-a-inferred-type-in-typescript/>
VANCOUVER
jarvispact | Sciencx - » TIL: How to get a live preview of a inferred type in typescript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/06/22/til-how-to-get-a-live-preview-of-a-inferred-type-in-typescript/
CHICAGO
" » TIL: How to get a live preview of a inferred type in typescript." jarvispact | Sciencx - Accessed . https://www.scien.cx/2022/06/22/til-how-to-get-a-live-preview-of-a-inferred-type-in-typescript/
IEEE
" » TIL: How to get a live preview of a inferred type in typescript." jarvispact | Sciencx [Online]. Available: https://www.scien.cx/2022/06/22/til-how-to-get-a-live-preview-of-a-inferred-type-in-typescript/. [Accessed: ]
rf:citation
» TIL: How to get a live preview of a inferred type in typescript | jarvispact | Sciencx | https://www.scien.cx/2022/06/22/til-how-to-get-a-live-preview-of-a-inferred-type-in-typescript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.