DEV Community

Christopher Kade
Christopher Kade

Posted on • Updated on • Originally published at christopherkade.com

Goodbye Typescript, hello native typing for Javascript ✨

Typing. Love it or hate it, it has many advantages: better DX (through intellisense auto-completion), better code documentation, less time consuming errors. Its benefits greatly outweigh its cost, so why do some people still avoid it? One word: Typescript. You have to set it up and make sure your tooling is working correctly which can add a layer of frustration to any project.

So what if I told you that native typing might be coming to Javascript? Christmas is right around the corner and boy do I have a gift for you 🎅

The proposal 📄

TC39 is the comity in charge of Javascript's specs - they help maintain and evolve the definition of JS. If you're curious, I wrote a section about them in a previous article.
They recently moved the Type Annotations proposal to Stage 1 (out of 4), which means it's time to widely speculate on the impact and implications of this feature !

As much as I love being dramatic, this will not sign the death of TS by any means, it will simply allow for cleaner and more reliable JS code for projects that don't plan on using TS or that wish to use both in conjunction.

What will native JS typing look like if this proposal passes?

It would be very close to what we currently have with Typescript and Flow, namely:

// both parameters are numbers, and this method returns a number
function add(a: number, b: number): number {
  return a + b;
}
Enter fullscreen mode Exit fullscreen mode

These annotations will not stop you from passing a string or any other variable type as parameter. They will be ignored at runtime and are just there as guidelines that can be used by 3rd party type checkers such as your IDE.

The argument for strict typing has its place in this discussion in my opinion. In its current proposal, these types are just type annotations, which is something we already have thanks to JSDoc. So the question remains: why?

What's the point? 🤷

We're in an odd situation: Javascript is one of the only languages that has us write in one language (Typescript) to then have it transpiled to another one (Javascript). These layers add complexity to any project, so the more tools we add to our default tool belt, the better.

The need for Typescript creates a form of monopoly on current available tooling, where each and everyone of them needs to evolve with TS in order to not be left behind. The State of the Octoverse 2022 shows the impressive popularity of Typescript in 2022, which means this need to evolve becomes almost mandatory for your linters, bundlers etc.

Having this feature already bundled with our dear Javascript will only make it a more complete package and help us slow down the obvious tooling bloat we're currently facing.


What do you think? Would you see yourself using this feature if it releases? What are the risks that come to mind, especially if you're an avid user of Typescript?

Feel free to follow me on Twitter (if it doesn't implode by the time you finish this article), it's always a pleasure connecting with some of you 😄

Latest comments (150)

Collapse
 
air_choosy profile image
priolo

as a priority: first this and then global warming

Collapse
 
timcharper profile image
Tim Harper

Inflammatory opinion, probably, but typescript is so good that you're really shooting yourself in the foot by not using it for a project of any moderate size or larger.

Collapse
 
flamesoff profile image
Artem

I don't really understand how software engineer can hate typing.

Collapse
 
tonioloewald profile image
Tonio Loewald

I'm so looking forward to this because I have found TypeScript a mixed bag, sometimes holding back use of new language features and definitely slowing down development (if sometimes improving quality).

A good thing. I hope it happens.

Collapse
 
ta4i profile image
Maks Kramarenko

I prefer TypeScript as it erases from resulting bundle by default. Therefore, it doesn't add weight to payload.

Collapse
 
jared201 profile image
Jared Odulio

I think it's part of a bigger [much sinister] vendor or a consortium agenda. Remember Java and Visual Basic when it was duopoly of Sun Microsystems and Microsoft? And then Asynchronous Javascript and XML(AJAX) was introduced and they lost control of the duopoly and their successors are trying to take control back with Typescript and domain-specific design systems (check what IBM is doing with Carbon) that are based on Web Components open standard. They can try but those days are never coming back.

Collapse
 
zacharyindy profile image
Zachary Indy

Let me laugh hard and harder...
The cost of abandoning ES4 back that day is damn expensive.
I mean long before TS and now the proposed typing on JS, ActionScript 3.0 has had such feature without the pain of dependencies, tools and other jokes.

Collapse
 
sumitsaurabh927 profile image
Sumit Saurabh

This looks promising!

Collapse
 
jimmywarting profile image
Jimmy Wärting

Oh no. They actually went ahead and put this in as a stage 1!? crap this worthless shit dose not give any type system features at all. this is crap it's only annotation and seen as comments by the js engine. this is worthless!

I'm all for typing but this dosen't benefit us in any way! this proposal is actually better: github.com/sirisian/ecmascript-types

Collapse
 
fbolaji profile image
Francis.B

Great! Definitely can't wait to use it.

Collapse
 
get2bumbumland profile image
Bob

"Javascript is one of the only languages that has us write in one language (Typescript) to then have it transpiled to another one (Javascript)."

Most software is written in compiled languages, where you write in one language and it is "transpiled" into machine language.

Collapse
 
sc7639 profile image
Scott Crossan

That would be a nice way to join typescript and JavaScript but without having an extra compile step. Especially if it’s ignored at run time

Collapse
 
ldrscke profile image
Christian Ledermann

This sounds great.
Just look at Python and the improvement that type annotations, static and run time type checking, and gradual typing brings with it.

Collapse
 
stojakovic99 profile image
Nikola Stojaković

Type annotations will become native to the language, which definitely simplified things as no 3rd-party solutions will be necessary.

TypeScript is not only about type annotations. Enums, tuples, generics, support for marking expression as constant thus narrowing it's type, conditional types, algebraic operations with types etc. If you're using TypeScript only for it's type annotations you're using only few percents of it's power.

Collapse
 
eerk profile image
eerk

You can already do this by setting “checkJS” to true in VS Code!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.