Riddle me this: TypeScript's latest data type is literally unknown

Version 3.0 improvements in Microsoft's lang also include pumped up tuples


Microsoft has rolled out version 3.0 of TypeScript, its open source extension of JavaScript that includes support for static types.

For those who love TypeScript – a growing group to judge by language rankings – or hate JavaScript – which often has something to do with its lack of static typing – that's not a bad way to start the week, apart from the breaking changes.

"TypeScript is an extension of JavaScript that aims to bring static types to modern JavaScript," said Daniel Rosenwasser, program manager on the TypeScript language at Microsoft, in a blog post. "The TypeScript compiler reads in TypeScript code, which has things like type declarations and type annotations, and emits clean readable JavaScript with those constructs transformed and removed."

That code can then be run in any ECMAScript runtime, such as a browser or Node.js, he explained.

To understand why that might be worthwhile, consider that JavaScript will let you create numerical and text variables and add them together, literally joining the two as a single string. In a strongly typed language, an error message would complain, to encourage the programmer to be specific about whether a number or string is the desired result.

A programming language that support data types helps makes type-related errors easier to catch and can reduce the amount of unit tests developers need to write to verify their code, though dealing with data types demands a bit more work up front.

TypeScript is the basis of the Angular front-end framework; the other leading front-end framework contender, React, can be used with TypeScript or with regular JavaScript. Facebook, which created React, also developed Flow, an open-source static type checker for JavaScript that serves as an alternative to TypeScript for those concerned about type checking.

TypeScript 3.0 adds a feature called "project references" that allows devs to specify how one TypeScript project depends on another, through paths added to tsconfig.json files that point to other configuration files.

Specifying such dependencies allows projects to be broken up into more manageable chunks and can accelerate builds. And there's now a --build flag to take advantage of incremental builds.

The updated TypeScript has also adapted to JavaScript's rest parameter syntax, by which a varying number of parameters can be passed to a function as arguments. Until version 3.0, TypeScript didn't have an efficient way to assign data types to this sort of operation.

Now the language treats rest parameters as generic and turns them into tuples, inferring the data types involved along the way. According to Rosenwasser, Microsoft's TypeScript team had to do some work on tuple types to make this work.

Error messages have also received some attention since last TypeScript release, making them shorter and clearer.

perl

Official: Perl the most hated programming language, say devs

READ MORE

There's a new data type, called unknown, that differs from another catch-all data type, called any. "Unlike any, unknown is assignable to almost nothing else without a type assertion," explains Rosenwasser. "You also can’t access any properties off of an unknown, nor can you call/construct them."

The unknown data type might be useful in a place where a dev wants to ensure that type checking is performed or that a type assertion is used. It also happens to represent one of the breaking changes – since unknown is now a reserved word, previous TypeScript code that used it as a variable name won't perform as expected.

Other additions to version 3.0 include broader JSX support (JSX being a JavaScript extension used in React) and a new reference directive for polyfills (libraries that make new APIs work with older runtimes).

"Going forward, we foresee bringing more value to the type system and tooling experience, polishing the existing work on project references, and making TypeScript (both the language and the project) more approachable by whatever means we can," said Rosenwasser. ®

Similar topics


Other stories you might like

  • Prisons transcribe private phone calls with inmates using speech-to-text AI

    Plus: A drug designed by machine learning algorithms to treat liver disease reaches human clinical trials and more

    In brief Prisons around the US are installing AI speech-to-text models to automatically transcribe conversations with inmates during their phone calls.

    A series of contracts and emails from eight different states revealed how Verus, an AI application developed by LEO Technologies and based on a speech-to-text system offered by Amazon, was used to eavesdrop on prisoners’ phone calls.

    In a sales pitch, LEO’s CEO James Sexton told officials working for a jail in Cook County, Illinois, that one of its customers in Calhoun County, Alabama, uses the software to protect prisons from getting sued, according to an investigation by the Thomson Reuters Foundation.

    Continue reading
  • Battlefield 2042: Please don't be the death knell of the franchise, please don't be the death knell of the franchise

    Another terrible launch, but DICE is already working on improvements

    The RPG Greetings, traveller, and welcome back to The Register Plays Games, our monthly gaming column. Since the last edition on New World, we hit level cap and the "endgame". Around this time, item duping exploits became rife and every attempt Amazon Games made to fix it just broke something else. The post-level 60 "watermark" system for gear drops is also infuriating and tedious, but not something we were able to address in the column. So bear these things in mind if you were ever tempted. On that note, it's time to look at another newly released shit show – Battlefield 2042.

    I wanted to love Battlefield 2042, I really did. After the bum note of the first-person shooter (FPS) franchise's return to Second World War theatres with Battlefield V (2018), I stupidly assumed the next entry from EA-owned Swedish developer DICE would be a return to form. I was wrong.

    The multiplayer military FPS market is dominated by two forces: Activision's Call of Duty (COD) series and EA's Battlefield. Fans of each franchise are loyal to the point of zealotry with little crossover between player bases. Here's where I stand: COD jumped the shark with Modern Warfare 2 in 2009. It's flip-flopped from WW2 to present-day combat and back again, tried sci-fi, and even the Battle Royale trend with the free-to-play Call of Duty: Warzone (2020), which has been thoroughly ruined by hackers and developer inaction.

    Continue reading
  • American diplomats' iPhones reportedly compromised by NSO Group intrusion software

    Reuters claims nine State Department employees outside the US had their devices hacked

    The Apple iPhones of at least nine US State Department officials were compromised by an unidentified entity using NSO Group's Pegasus spyware, according to a report published Friday by Reuters.

    NSO Group in an email to The Register said it has blocked an unnamed customers' access to its system upon receiving an inquiry about the incident but has yet to confirm whether its software was involved.

    "Once the inquiry was received, and before any investigation under our compliance policy, we have decided to immediately terminate relevant customers’ access to the system, due to the severity of the allegations," an NSO spokesperson told The Register in an email. "To this point, we haven’t received any information nor the phone numbers, nor any indication that NSO’s tools were used in this case."

    Continue reading

Biting the hand that feeds IT © 1998–2021