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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.