Lead Product Evangelist @Kentico, Founding partner @craftbrewingbiz. love to learn / teach web dev & software engineering, collecting vinyl records, mowing my lawn, craft 🍺
I get the feeling Martin meant 3rd party libraries that don't have typings defined (if written in JavaScript) or are written in Typescript but don't provide their own robust types for APIs.
This can definitely happen, though it's a lot less common (and painful) than it was 3-4 years ago.
I recently used an Angular-specific 3rd party library for authentication. They didn't include types for some of their underlying JavaScript code.
I had the option of either using :any as the type (or leaving the type off, as it will default to :any) or writing my own types to describe their JavaScript APIs.
I wrote out some type definitions that covered the part of their APIs that I was using and the definitions took about 15 minutes after looking at the JavaScript code in the package under /node_modules.
If you decide to use :any (or, again, leave off any type annotations, which works fine) you are where you would be with plain JavaScript - so nothing lost.
If you add type annotations, you gain all the benefits of types - my favorite being discoverability of APIs.
Right, It made more sense after reading more about it. I think the discoverability in general is such a nice thing you get by going with static types that is almost worth it by that alone haha
Lead Product Evangelist @Kentico, Founding partner @craftbrewingbiz. love to learn / teach web dev & software engineering, collecting vinyl records, mowing my lawn, craft 🍺
But, Typescript knows that name is a string and anywhere I use name, either as a parameter or in an assignment or expression, Typescript will flow that string type to the next place I'm working with name.
A lot of developers when first using Typescript will add a ton of annotations to their code, only to realize later that Typescript is great at inferring type information and doesn't need us to be so explicit.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I get the feeling Martin meant 3rd party libraries that don't have typings defined (if written in JavaScript) or are written in Typescript but don't provide their own robust types for APIs.
This can definitely happen, though it's a lot less common (and painful) than it was 3-4 years ago.
I recently used an Angular-specific 3rd party library for authentication. They didn't include types for some of their underlying JavaScript code.
I had the option of either using
:any
as the type (or leaving the type off, as it will default to:any
) or writing my own types to describe their JavaScript APIs.I wrote out some type definitions that covered the part of their APIs that I was using and the definitions took about 15 minutes after looking at the JavaScript code in the package under
/node_modules
.If you decide to use
:any
(or, again, leave off any type annotations, which works fine) you are where you would be with plain JavaScript - so nothing lost.If you add type annotations, you gain all the benefits of types - my favorite being discoverability of APIs.
Right, It made more sense after reading more about it. I think the discoverability in general is such a nice thing you get by going with static types that is almost worth it by that alone haha
Another nice thing about Typescript is how the types "flow" through the application.
Often I only need to annotate a couple of parameters, variables, methods.
Then when using those things the rest of my code is able to infer the results of operations.
For example:
Notice, there are 0 type annotations here...
But, Typescript knows that
name
is astring
and anywhere I use name, either as a parameter or in an assignment or expression, Typescript will flow thatstring
type to the next place I'm working withname
.A lot of developers when first using Typescript will add a ton of annotations to their code, only to realize later that Typescript is great at inferring type information and doesn't need us to be so explicit.