-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
https://devblogs.microsoft.com/typescript/announcing-typescript-4-4-rc/
This issue is just to track all of the new features and their implementation state in this project.
As with all releases, we will not necessarily to support all features until closer to the full release when everything the features are stabilised.
Please be patient.
Control Flow Analysis of Aliased Conditions
function foo(arg: unknown) {
const argIsString = typeof arg === "string";
if (argIsString) {
console.log(arg.toUpperCase());
// ~~~~~~~~~~~
// Error! Property 'toUpperCase' does not exist on type 'unknown'.
}
}
This requires no AST changes, and should just improve all of our rules.
Symbol Pattern and Template String Pattern Index Signatures
interface Colors {
[sym: symbol]: number;
}
interface OptionsWithDataProps {
// Permit any property starting with 'data-'.
[optName: `data-${string}`]: unknown;
}
This requires no AST changes, as we already support this via TSIndexSignature > Identifier.parameters > TSTypeAnnotation.typeAnnotation
. Once TS supports the syntax, we will too.
Defaulting to the unknown
Type in Catch Variables (--useUnknownInCatchVariables)
try {
executeSomeThirdPartyCode();
}
catch (err) { // err: unknown
// Error! Property 'message' does not exist on type 'unknown'.
console.error(err.message);
// Works! We can narrow 'err' from 'unknown' to 'Error'.
if (err instanceof Error) {
console.error(err.message);
}
}
This requires no AST changes, and in fact makes the no-implicit-any-catch
obsolete!
Breaking Changes -> Abstract Properties Do Not Allow Initializers (support #3765)
abstract class C {
abstract prop = 1;
// ~~~~
// Property 'prop' cannot have an initializer because it is marked abstract.
}
We can update our AST to remove the value
property from TSAbstractClassProperty
.
Given that this node shares the AST structure of normal class properties - it's probably not worth updating the AST spec though.
Class Static Blocks (support #3730)
class Foo {
static Foo.count = 0;
// This is a static block:
static {
if (someCondition()) {
Foo.count++;
}
}
}
This will require AST changes.
Other changes with no AST impact to us
- Exact Optional Property Types (
--exactOptionalPropertyTypes
) tsc --help
Updates and Improvements- Performance Improvements
- Faster Declaration Emit
- Faster Path Normalization
- Faster Path Mapping
- Faster Incremental Builds with
--strict
- Faster Source Map Generation for Big Outputs
- Faster
--force
Builds
- Spelling Suggestions for JavaScript
- Inlay Hints
- Auto-Imports Show True Paths in Completion Lists
- Breaking Changes
lib.d.ts
Changes for TypeScript 4.4- More-Compliant Indirect Calls for Imported Functions
- Using
unknown
in Catch Variables - Broader Always-Truthy Promise Checks