As the Microsoft team said of 3:0’s release: “At its core, this experience means analysing your code to catch things like bugs and typos before your users run into them.”
A data type, called “unknown”? Yes, the TypeScript team have created this datatype to improve type safety, which the team claims will help programmers to safely declare types of data that are not known until a later point (runtime).
Traditionally, developers have used the keyword ‘any’ which supports any data type, to handle such scenarios, however this approach does not enforce type safety because ‘any’ can be assigned to anything.
In contrast, ‘unknown’ can only be assigned to a variable once a data type has been subsequently defined using type assertion (essentially telling the data what to look like).
The team states in the release notes: “TypeScript 3.0 introduces a new top type unknown. unknown is the type-safe counterpart of any. Anything is assignable to unknown, but unknown isn’t assignable to anything but itself and any without a type assertion or a control flow based narrowing. Likewise, no operations are permitted on an unknown without first asserting or narrowing to a more specific type.”
Function Parameter Lists as Tuple Types
Parameter lists as tuple types enable developers to interact with function parameters as tuples, meaning that parameters can be assigned types using tuples.
The TypeScript team explains that this will give developers more power when handling data passed into function parameters: “With these features it becomes possible to strongly type a number of higher-order functions that transform functions and their parameter lists”.
This feature was asked for via GitHub in 2015, by a user who does not appear to be on the team themselves; good to see Microsoft listening to the community. With even more features outlined in the release notes, it’s clear that Microsoft’s TypeScript continues to deliver real world value to developers.
This article is from the CBROnline archive: some formatting and images may not be present.
Join Our Newsletter
Want more on technology leadership?
Sign up for Tech Monitor's weekly newsletter, Changelog, for the latest insight and analysis delivered straight to your inbox.