TypeScript


TypeScript is a programming language that is a superset of JavaScript. It was developed by Microsoft and first released in 2012. TypeScript is designed to add optional static type checking to JavaScript, making it easier to develop large-scale applications.

TypeScript compiles to plain JavaScript and can run on any browser or JavaScript engine. The TypeScript compiler is available as a command-line tool or can be integrated into popular IDEs such as Visual Studio Code.

TypeScript adds several features to JavaScript, including:

Optional static typing: Variables, function parameters, and return types can be explicitly typed, and the compiler can check that types are used consistently throughout the code. This can help catch certain types of errors at compile-time instead of at run-time.
Class-based object-oriented programming: TypeScript supports class-based object-oriented programming with interfaces, inheritance, and encapsulation.
Type annotations and type inference: TypeScript can automatically infer types for variables and expressions, or types can be explicitly annotated for better readability and error checking.
Advanced features: TypeScript supports many advanced features, such as async/await, decorators, and generics.
TypeScript also includes the features of the latest ECMAScript standards and provides backward compatibility with earlier versions of JavaScript.

Why Using TypeScript over JavaScript?

Syntax

See @thilliezTypeScriptSyntaxCheatsheets2023 (private) or https://www.typescriptlang.org/cheatsheets (public)

TsConfig

{
	"compilerOptions": {
		"lib" : [ "DOM", "ES6" ],
		"outDir": "dist",	
		"strict": true,		
		"target" : "ES3",
	}
}

tsconfig.json is a configuration file used by the TypeScript compiler to specify compiler options and other settings for a TypeScript project. It is a JSON file that must be located in the root of your project directory.

Here are some of the possible settings that can be specified in tsconfig.json:

Map Files

map.js files are source map files generated by the TypeScript compiler when the sourceMap compiler option is set to true. These files allow developers to map the compiled JavaScript code back to the original TypeScript source code.

When you write TypeScript code, it gets transpiled to JavaScript code that can be executed by a browser or Node.js environment. However, this compiled code can be difficult to read and debug, especially if you are working with a large codebase. This is where source maps come in.

Source maps provide a mapping between the compiled JavaScript code and the original TypeScript code. This mapping allows developers to view and debug the TypeScript code directly in the browser or in their favorite debugging tools, even though the code that's actually running is the compiled JavaScript code.

The map.js file contains this mapping information. When a developer debugs the JavaScript code, the browser or debugging tool uses the source map file to display the corresponding TypeScript code.

META

Status:: #wiki/notes/mature
Plantations:: Programming Languages
References:: ILOG