-
Notifications
You must be signed in to change notification settings - Fork 12.6k
API Breaking Changes
-
visitNode
'slift
Takes areadonly Node[]
Instead of aNodeArray<Node>
The
lift
function in thevisitNode
API now takes areadonly 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:
f<T>(100)
TypeScript will parse it as the following JavaScript:
(f < T) > (100)
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 toTupleTypeNode.elements
. -
KeywordTypeNode
is no longer used to representthis
andnull
types.null
now gets aLiteralTypeNode
,this
now always gets aThisTypeNode
. -
TypeChecker.typeToTypeNode
now correctly produces aLiteralTypeNode
fortrue
andfalse
types, which matches the behavior in the parser. Prior to this the checker was incorrectly returning thetrue
andfalse
tokens themselves, which are indistinguishable from expressions when traversing a tree.
- The mutable property
disableIncrementalParsing
has been removed. It was untested and, at least on GitHub, unused by anyone. Incremental parsing can no longer be disabled.
-
the
typeArguments
property has been removed from theTypeReference
interface, and thegetTypeArguments
method onTypeChecker
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.
function getTypeArguments(checker: ts.TypeChecker, typeRef: ts.TypeReference) { return checker.getTypeArguments?.(typeRef) ?? (typeRef as any).typeArguments; }
-
SymbolFlags.JSContainer
has been renamed toSymbolFlags.Assignment
to reflect that Typescript now supports expando assignments to functions.
- The deprecated internal method
LanguageService#getSourceFile
has been removed. See #24540. - The deprecated function
TypeChecker#getSymbolDisplayBuilder
and associated interfaces have been removed. See #25331. The emitter and node builder should be used instead. - The deprecated functions
escapeIdentifier
andunescapeIdentifier
have been removed. Due to changing how the identifier name API worked in general, they have been identity functions for a few releases, so if you need your code to behave the same way, simply removing the calls should be sufficient. Alternatively, the typesafeescapeLeadingUnderscores
andunescapeLeadingUnderscores
should be used if the types indicate they are required (as they are used to convert to or from branded__String
andstring
types). - The
TypeChecker#getSuggestionForNonexistentProperty
,TypeChecker#getSuggestionForNonexistentSymbol
, andTypeChecker#getSuggestionForNonexistentModule
methods have been made internal, and are no longer part of our public API. See #25520.
-
getJsxIntrinsicTagNames
has been removed and replaced withgetJsxIntrinsicTagNamesAt
, which requires a node to use as the location to look up the valid intrinsic names at (to handle locally-scoped JSX namespaces).
- Some services methods (
getCompletionEntryDetails
andgetCompletionEntrySymbols
) have additional parameters. Plugins that wrap the language service must pass these parameters along to the original implementation. See #19507
-
Symbol.name
,Symbol.getName()
, andIdentifier.text
are all now of type__String
. This is a special branded string to help track where strings are appropriately escaped and prevent their misuse.escapeIdentifier
andunescapeIdentifier
has been renamed toescapeLeadingUnderscores
andunescapeLeadingUnderscores
and had their types updated accordingly. Deprecated versions ofescapeIdentifier
andunescapeIdentifier
still exist with the old name and type signature, however they will be removed in a future version. See #16915.
-
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
, andprotocol.ScriptTarget
. Also,ts.CommandNames
is now an alias forprotocol.CommandTypes
. See #15966 and #16425. -
The type
EnumLiteralType
was removed andLiteralType
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 aname
property. TypeScript now recognize assignments in .js files as declarations in certain contexts, e.g.func.prototype.method = function() {..}
will be a declaration of membermethod
onfunc
. As a resultDeclaration
is not guaranteed to have aname
property as before. A new type was introducedNamedDeclaration
to take the place ofDeclaration
, andDeclaration
moved to be the base type of bothNamedDeclaration
andBinaryExpression
. Casting toNamedDeclaration
should be safe for non .js declarations. See #15594 for more details.
-
ts.Map<T>
is now a nativeMap<string, T>
or a shim. This affects theSymbolTable
type, exposed bySymbol.members
,Symbol.exports
, andSymbol.globalExports
.
-
ParseConfigHost
now requires a new memberreadFile
to support configuration inheritance.
-
LanguageService.getSourceFile
has been removed;LanguageService.getProgram().getSourceFile
should be used instead.
-
ts.parseConfigFile
has been renamed tots.parseJsonConfigFileContent
-
return type of
CompilerHost.resolveModuleNames
was changed fromstring[]
toResolvedModule[]
. Extra optional propertyisExternalLibraryImport
in ResolvedModule interface denotes ifProgram
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:- should be a 'd.ts' file
- should be an external module
- should not contain tripleslash references.
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)
-
TypeChecker.emitFiles
is no longer available; useProgram.emit
instead. - Getting diagnostics are now all centralized on Program,
- for Syntactic diagnostics for a single file use:
Program.getSyntacticDiagnostics(sourceFile)
- for Syntactic diagnostics for all files use:
Program.getSyntacticDiagnostics()
- for Semantic diagnostics for a single file use:
Program.getSemanticDiagnostics(sourceFile)
- for Semantic diagnostics for all files use:
Program.getSemanticDiagnostics()
- for compiler options and global diagnostics use:
Program.getGlobalDiagnostics()
- for Syntactic diagnostics for a single file use:
Tip: use ts.getPreEmitDiagnostics(program) to get syntactic, semantic, and global diagnostics for all files
Here are the details:
-
CompilerHost.getDefaultLibFilename
=>CompilerHost.getDefaultLibFileName
-
SourceFile.filename
=>SourceFile.fileName
-
FileReference.filename
=>FileReference.fileName
-
LanguageServiceHost.getDefaultLibFilename
=>LanguageServiceHost.getDefaultLibFileName
-
LanguageServiceShimHost.getDefaultLibFilename
=>LanguageServiceShimHost.getDefaultLibFileName
The full list of APIs can be found in this commit
The syntacticClassifierAbsent
parameter for the Classifier.getClassificationsForLine is now required
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:
- Commit 2ee134c6b3c0ec
- Commit 35dde28d44122c
- Commit c9ef4db99ac93bb1c166a
- Commit b4e5d5b0b460cc88a10db
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
- Performance
- Performance-Tracing
- Debugging-Language-Service-in-VS-Code
- Getting-logs-from-TS-Server-in-VS-Code
- JavaScript-Language-Service-in-Visual-Studio
- Providing-Visual-Studio-Repro-Steps
Contributing to TypeScript
- Contributing to TypeScript
- TypeScript Design Goals
- Coding Guidelines
- Useful Links for TypeScript Issue Management
- Writing Good Design Proposals
- Compiler Repo Notes
- Deployment
Building Tools for TypeScript
- Architectural Overview
- Using the Compiler API
- Using the Language Service API
- Standalone Server (tsserver)
- TypeScript MSBuild In Depth
- Debugging Language Service in VS Code
- Writing a Language Service Plugin
- Docker Quickstart
FAQs
The Main Repo