Загрузка видео...

Не удалось загрузить видео

На главную

Did you know TypeScript <Generics> don't always need to be explicitly set? You can infer their types by the type of data being passed! Super powerful approach when writing library or util code.

57,847 просмотров • 3 лет назад •via X (Twitter)

Комментарии: 11

Фото профиля Ozzy
Ozzy3 лет назад

Woah woah woah. What is this type hunting you’ve got there!?

Фото профиля Wes Bos
Wes Bos3 лет назад

It's called InlayHints - takes a bit to dialed in as there are lots of options, but it's been in VS code for a bit now. Your theme also needs to support it

Фото профиля Arnab Chatterjee
Arnab Chatterjee3 лет назад

I explored it today only

Фото профиля Jigal Sanders
Jigal Sanders3 лет назад

Hell this is typescript and I actually understood it.

Фото профиля Ricardo Busquet
Ricardo Busquet3 лет назад

that's the main usage for generics and I do feel the TS community doesn't use it as we should. The point of generics is to allow for writing code that works for any types while adding constraints on the inputs and outputs so the interfaces are always safe.

Фото профиля Wes Bos
Wes Bos3 лет назад

Agreed, but the point isn't to let them always be inferred - not sure if that is what you meant. It's often handy to specify the type explicitly and then be able to safely type the arguments of a function

Фото профиля Simon Taylor
Simon Taylor3 лет назад

Why we need your TS course 🥲 are you planning to release anytime soon Wes?

Фото профиля JavascriptEnthu(Shakil)
JavascriptEnthu(Shakil)3 лет назад

Typescript is much needed for me. And I am on my way

Фото профиля Sock, the dev 🧦
Sock, the dev 🧦3 лет назад

A little gotcha to be aware of that bit me, is if you have two or more generic parameters; function foo<ParamOne, ParamTwo = unknown>( one: ParamOne, two: ParamTwo ) If you pass in only the first generic arg (foo<String>), the rest won't be inferred. It's all or nothing.

Фото профиля Ebn Sina
Ebn Sina3 лет назад

Will be ever your typescript course will be launch? It's been so long!

Фото профиля Wes Bos
Wes Bos3 лет назад

It has - I'm almost done .Should have some updates on it soon

Похожие видео