A simple introduction to Typescript
A brief introduction to some concepts of Typescript
The compiler can be configured to check for type errors, and will report errors if any are found. Type checking can be disabled if desired. The TypeScript compiler is available under the Apache 2.0 open source license.
Not a strongly-typed language
Typescript is not a strongly-typed language because it does not require variables to be declared with a specific type. This means that a variable can be declared as one type and then reassigned to a value of another type. This can lead to errors if the variable is used in a way that is not compatible with the type that it has been declared as.
A basic example to illustrate this characteristic can be shown with the type "any".
// We initialze the variable as a string. const something: any = "Tom"; // Now it's a number. This is valid TypeScript code. something = 42;
TypeScript language server
The TypeScript language server is a language server that provides features such as code completion, go-to-definition, and type checking for TypeScript projects.
The language server is required for the TypeScript compiler to be able to provide these features. Without the language server, the TypeScript compiler would only be able to provide basic features such as syntax highlighting and code formatting. The TypeScript language server is open source and available on GitHub.
Steps to create a TypeScript project
Before describing the steps, here's the command to initialize a TypeScript project in your terminal.
Description: Install the TypeScript compiler. Create a
tsconfig.json file in the root of the project. This file contains the compiler options for the TypeScript compiler. Add the src directory to the tsconfig.json file. This is where the TypeScript source files will be located.
main.js from the command line.
TypeScript uses an optional type system, which means that types can be specified for variables, but it is not required. Other strongly-typed languages, such as Swift and Kotlin, use a mandatory type system, which requires all variables to be declared with a specific type.
If a project is starting from scratch, it is usually best to use TypeScript. This will allow for better code organization and maintenance in the long run.
Check the links in the addendum at the end of the page for some useful learning materials.