We read every piece of feedback, and take your input very seriously.
Include my email address so I can be contactedAs part of an optimization on substitution types, SubstitutionType objects no longer contain the substitute property representing the effective substitution (usually an intersection of the base type and the implicit constraint) - instead, they just contain the constraint property.
For more details, read more on the original pull request.
The current direction of decorators in TC39 means that TypeScript will have to handle a break in terms of placement of decorators. Previously, TypeScript assumed decorators would always be placed prior to all keywords/modifiers. For example
Decorators as currently proposed do not support this syntax. Instead, the export keyword must precede the decorator.
Unfortunately, TypeScript's trees are concrete rather than abstract, and our architecture expects syntax tree node fields to be entirely ordered before or after each other. To support both legacy decorators and decorators as proposed, TypeScript will have to gracefully parse, and intersperse, modifiers and decorators.
To do this, it exposes a new type alias called ModifierLike which is a Modifier or a Decorator.
Decorators are now placed in the same field as modifiers which is now a NodeArray<ModifierLike> when set, and the entire field is deprecated.
All existing decorators properties have been marked as deprecated and will always be undefined if read. The type has also been changed to undefined so that existing tools know to handle them correctly.
To avoid all deprecation warnings and other issues, TypeScript now exposes four new functions. There are individual predicates for testing whether a node has support modifiers and decorators, along with respective accessor functions for grabbing them.
As an example of how to access modifiers off of a node, you can write
With the note that each call to getModifiers and getDecorators may allocate a new array.
For more information, see changes around
factory.createImportSpecifier and factory.updateImportSpecifier now take an isTypeOnly parameter:
You can read more about this change at the implementing PR.
visitNode's lift Takes a readonly Node[] Instead of a NodeArray<Node>
The lift function in the visitNode API now takes a readonly Node[]. You can see details of the change here.
Type Arguments in JavaScript Are Not Parsed as Type Arguments
Type arguments were already not allowed in JavaScript, but in TypeScript 4.1, the parser will parse them in a more spec-compliant way. So when writing the following code in a JavaScript file:
TypeScript will parse it as the following JavaScript:
This may impact you if you were leveraging TypeScript's API to parse type constructs in JavaScript files, which may have occurred when trying to parse Flow files.
TypeScript provides a set of "factory" functions for producing syntax tree nodes; however, TypeScript 4.0 provides a new node factory API. For TypeScript 4.0 we've made the decision to deprecate these older functions in favor of the new ones. For more details, read up on the relevant pull request for this change.
TupleTypeNode.elementTypes renamed to TupleTypeNode.elements.
KeywordTypeNode is no longer used to represent this and null types. null now gets a LiteralTypeNode, this now always gets a ThisTypeNode.
TypeChecker.typeToTypeNode now correctly produces a LiteralTypeNode for true and false types, which matches the behavior in the parser. Prior to this the checker was incorrectly returning the true and false tokens themselves, which are indistinguishable from expressions when traversing a tree.
the typeArguments property has been removed from the TypeReference interface, and the getTypeArguments method on TypeChecker instances should be used instead. This change was necessary to defer resolution of type arguments in order to support recursive type references.
As a workaround, you can define a helper function to support multiple versions of TypeScript.
The following types/namespaces are now string enums: ts.Extension, ts.ScriptElementKind, ts.HighlightSpanKind, ts.ClassificationTypeNames, protocol.CommandTypes, protocol.IndentStyle, protocol.JsxEmit, protocol.ModuleKind, protocol.ModuleResolutionKind, protocol.NewLineKind, and protocol.ScriptTarget. Also, ts.CommandNames is now an alias for protocol.CommandTypes. See #15966 and #16425.
The type EnumLiteralType was removed and LiteralType is used instead. LiteralType also replaces .text with a .value which may be either a number or string. See String valued members in enums.
Declaration does not have a name property. TypeScript now recognize assignments in .js files as declarations in certain contexts, e.g. func.prototype.method = function() {..} will be a declaration of member method on func. As a result Declaration is not guaranteed to have a name property as before. A new type was introduced NamedDeclaration to take the place of Declaration, and Declaration moved to be the base type of both NamedDeclaration and BinaryExpression. Casting to NamedDeclaration should be safe for non .js declarations. See #15594 for more details.
return type of CompilerHost.resolveModuleNames was changed from string[] to ResolvedModule[]. Extra optional property isExternalLibraryImport in ResolvedModule interface denotes if Program should apply some particular set of policies to the resolved file. For example if Node resolver has resolved non-relative module name to the file in 'node_modules', then this file:
Rationale: files containing external typings should not pollute global scope (to avoid conflicts between different versions of the same package). Also such files should never be added to the list of compiled files (otherwise compiled .ts file might overwrite actual .js file with implementation of the package)
Tip: use ts.getPreEmitDiagnostics(program) to get syntactic, semantic, and global diagnostics for all files
Here are the details:
The full list of APIs can be found in this commit
See Pull Request #2051 for more details.
TextChange.start and TextChange.length became properties instead of methods.
SourceFile.getLineAndCharacterFromPosition became SourceFile.getLineAndCharacterOfPosition
We did some cleanup to the public interfaces, here is the full list of changes:
The two files exposed helpers in the past that were not part of the supported TypeScript API. If you were using any of these APIs please file an issue to re-expose them; requests for exposing helper APIs will be triaged on a case-by-case basis.
For more information please see the full change.
News
Debugging TypeScript
Contributing to TypeScript
Building Tools for TypeScript
FAQs
The Main Repo