Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 22, 2022 03:50 pm GMT

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 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


Original Link: https://dev.to/jarvispact/til-how-to-get-a-live-preview-of-a-inferred-type-in-typescript-592

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To