Description
https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/
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.
Template Literal Types
type World = "world";
type Greeting = `hello ${World}`;
//
type Color = "red" | "blue";
type Quantity = "one" | "two";
type SeussFish = `${Quantity | Color} fish`;
//
type VerticalAlignment = "top" | "middle" | "bottom";
type HorizontalAlignment = "left" | "center" | "right";
// Takes
// | "top-left" | "top-center" | "top-right"
// | "middle-left" | "middle-center" | "middle-right"
// | "bottom-left" | "bottom-center" | "bottom-right"
declare function setAlignment(value: `${VerticalAlignment}-${HorizontalAlignment}`): void;
type EnthusiasticGreeting<T extends string> = `${Uppercase<T>} - ${Lowercase<T>} - ${Capitalize<T>} - ${Uncapitalize<T>}`;
type HELLO = EnthusiasticGreeting<"heLLo">;
// same as
// type HELLO = "HELLO - hello - Hello - heLLo";
This will require new AST nodes.
Key Remapping in Mapped Types
type MappedTypeWithNewKeys<T> = {
[K in keyof T as NewKeyType]: T[K]
// ^^^^^^^^^^^^^
// This is the new syntax!
}
This will require AST changes.
Recursive Conditional Types
type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T;
This will require no changes.
Pedantic Index Signature Checks
Example with the noUncheckedIndexedAccess
compiler option turned on:
function screamLines(strs: string[]) {
// this will have issues
for (let i = 0; i < strs.length; i++) {
console.log(strs[i].toUpperCase());
// ~~~~~~~
// error! Object is possibly 'undefined'.
}
}
This will require no changes (it will just start working and improve existing rules like no-unnecessary-condition
for free!)
React 17 JSX Factories
This will require a slight tweak to how the parser
passes options to scope-manager
Other changes that have no impact on us:
-
paths
withoutbaseUrl
-
checkJs
ImpliesallowJs
-
Editor Support for the JSDoc
@see
Tag -
abstract
Members Can’t Be Markedasync
- we don't throw parser errors for invalid syntax (yet Parsing: strictly enforce the produced AST matches the spec and enforce most "error recovery" parsing errors #1852)
-
any
/unknown
Are Propagated in Falsy Positions -
--declaration
and--outFile
Requires a Package Name Root -
resolve
's Parameters Are No Longer Optional inPromise
s