Skip to main content

TSCCLI Dev tool to Type-Check/Compile TS to JS

aka TSC, TypeScript-Standalone-Compiler, TypeScript-Compiler, TS-Standalone-Compiler, TS-Compiler

uses static code analysis to reduce Runtime Error

TS Compiler will throw errors or provide warnings before executing code - helps catch easy mistakes like typos

high-level compiler that takes a TS file and outputs and JS file

Type annotations erased from JS file due to lack of TypeScript compatibility with browsers & runtimes

TS Errors

Type Assertion

TS Syntax to override TSC's Type Inference for Static Type of specific Value

Type Inference

(feature) TSC to auto-derive implicit Type for Variable (w/o explicit Type Annotation)

TSC commands

default tsc transpiles .ts to .js - even if type errors occur

prevent TS compiler updating index.ts to js file if type error found

tsc --noEmitOnError index.ts

TSC Strictness Config

TSC Directive

comment statement as Directive to control TSC behavior on line/file basis

References

  1. --noImplicitAny ↔ to flag TSC to prevent Type Inference for any - enforce explicit Type for Parameter, Exception, etc

  2. Language Servicecomponent layer of TSC to provide tool integration with IDE for more features

  3. tsc --strict ↔ to flag TSC auto-set max strictness settings, apply true to: --noImplicitAny, --noImplicitThis, --alwaysStrict, --strictNullChecks, --strictFunctionTypes, --strictPropertyInitialization

  4. --noImplicitThis ↔ to flag TSC to throw error when Type of this keyword unclear

  5. --strictNullChecks ↔ to flag TSC to throw error when null is not explicitly defined

  6. --strictFunctionTypes ↔ to flag TSC to enforce stronger checks for function Types

  7. --strictPropertyInitialization ↔ flag to set TSC to throw error when properties in class definitions are not initialized

  8. Type Inference ↔ (feature) TSC to auto-derive implicit Type for Variable (w/o explicit Type Annotation)

  9. tsconfig.jsonTS Manifest to config TSC behavior

  10. run [**_TSC_**](tsc_ts-def) in root folder which has typescript config filetsc

npx tsc
  1. // @ts-nocheck` ↔ tell TSC to not Type-Check this file

  2. // @ts-check` ↔ tell TSC to check this (JS?) file

  3. // @ts-expect-error` ↔ tell TSC to expect & suppress static error on next line

  4. Watch ModeTSC mode to continuously monitor & recompile upon Code change (save)

  5. run [**_TSC_**](tsc_ts-def) in [Watch Mode](watch-mode) for app.tstsc app.ts -w

  6. "exclude": ["_FILE_PATHS", "_OR_ENTIRE_FOLDERS_"] ↔ to exclude file/dir from TSC

  7. "files": ["_FILEONLY_"] ↔ to include file for TSC

  8. "lib": [] ↔ to set which default objects & features TSC knows

  9. Type AssertionTS Syntax to override TSC's Type Inference for Static Type of specific Value

  10. Generic Type ↔ factory for Types, defined using Angle Bracket Notation, to annotate with Generic Type Placeholder for TSC to infer & fill in

  11. function type inferenceTSC only infers Type of return values, ignores Type of param args

  12. // @ts-ignore ↔ tell TSC to ignore Type-Check for next line only

  13. TSC Directive ↔ comment statement as Directive to control TSC behavior on line/file basis

  14. --alwaysStrict ↔ to flag TSC to apply Strict Mode

  15. tsc --init ↔ init TSC in project w/o TS