🔍 what is typescript
JavaScript and More
TypeScript adds additional syntax to JavaScript to support a tighter integration with your editor. Catch errors early in your editor.
- TypeScript adds additional syntax to JavaScript to enable tighter integration with the editor. Catch errors early in the editor.
A Result You Can Trust
TypeScript code converts to JavaScript which runs anywhere JavaScript runs: In a browser, on Node.js or Deno and in your apps.
- TypeScript code can be converted to JavaScript and run wherever JavaScript runs: in a browser, on Node.js or Deno, or in your application.
Safety at Scale
TypeScript understands JavaScript and uses type inference to give you great tooling without additional code.
- TypeScript understands JavaScript and uses type inference to give you great tools that require no extra code.
Install the typescript
The installation
# npm
npm install typescript -D
# yarn
yarn add typescript -D
Copy the code
Run the typescript compiler
NPX TSC or YARN TSCCopy the code
🔧 Tsconfig. Json configuration
The presence of a
tsconfig.json
file in a directory indicates that the directory is the root of a TypeScript project. Thetsconfig.json
file specifies the root files and the compiler options required to compile the project.
- Manually create
tsconfig.json
Content is{}
- Automatically generate
npx tsc --init
The tsconfig.json file in the TypeScript project root directory specifies the root file and compiler options required to compile the project. TypeScript will include all.ts files in the directory and subdirectories that contain the tsconfig.json file as part of the compilation context.
{
"compilerOptions": {},
"files": [
"src/hello.ts"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
Copy the code
compilerOptions
Configure compilation optionsfiles
Explicitly specify the file to compileinclude
Included filesexclude
Excluded file
Where path and file support wildcard characters, where/ * * *
Represents all files under all paths
Compiling ts files
The compilation process is to convert ts files into JS files
- Compiling and formulating documents
npx tsc hello.ts
- Compile from the configuration file
npx tsc --init
npx tsc
- Listen for file changes to compile automatically
npx tsc -w filePath