Explanation on the role of Typescript's target and lib settings
In simple terms, think of the target
as determining the syntax of the resulting JavaScript code, while the lib
specifies the API members that your TypeScript code can utilize. For more in-depth information, refer to these resources:
- Typescript- What is target in tsconfig?
- What does the tsconfig option "lib" do?
...it doesn't seem to convert es2017 constructs to es5... Is this intentional or am I overlooking a setting in tsconfig.json?
Indeed, this behavior is intentional. When transpiling, TypeScript only converts the syntax according to the specified target
; it does not automatically fill in missing API members from the target
. A member of the TypeScript team elaborated on this concept in a GitHub comment, stating:
I think you're confusing transpilation with auto-polyfilling. TypeScript doesn't automatically polyfill like Babel, but it does handle syntactic transformations (e.g., arrow functions). To use ES6 runtime methods, include the necessary polyfills along with their definition files.
If your lib
includes API members (such as Array.prototype.include
) absent in the target
, you must install corresponding polyfills to provide those functionalities.