Basic features of the JavaScript type system

These are features that often confuse because they work differently from those in other programming languages. Understanding these features make working with TypeScript easier because they provide insight into the problems that TypeScript solves.
Process di Javascript, 11 months ago

Basically JavaScript is:

  1. JavaScript will attempt to convert data types when they
are combined with an operator.
  2. JavaScript functions can be defined with a literal syntax
 that declares parameters and a function body or using
 the fat arrow/lambda function syntax.
  3. JavaScript functions can accept a variable number of
 arguments, which can be captured using a rest 
parameter.
  4. JavaScript functions do not formally declare results and
 can return any result type.
  5. JavaScript arrays are variable-length and can accept 
values of any type.
  6. JavaScript objects are a collection of properties and
 values and can be defined using a literal syntax.
  7. JavaScript objects can be altered to add, change, or
 remove properties.
  8. JavaScript objects can be defined with methods, which 
are functions assigned to a property.
  9. The this keyword refers to different objects depending
 on how functions are invoked.

JavaScript features for dealing with objects, sequences of values, collections, and the use of modules. These are all JavaScript features, but, as you will learn, understanding them helps put TypeScript into context and sets the foundation for effective TypeScript development. JavaScript objects have a prototype from which they inherit properties and methods.

  1. Objects can be created in a literal form or using a constructor function.
  2. JavaScript classes create a consistent template for creating objects.
  3. JavaScript classes support private fields, properties, and methods.
  4. Iterators and generators produce sequences of values.
  5. JavaScript objects and arrays can be used as simple collections, but you can also use a built-in map collection.
  6. Modules are used to structure a project, using either the ECMAScript or CommonJS module formats.

TypeScript compiler, which is responsible for transforming TypeScript code into pure JavaScript.

  1. TypeScript projects have a structure that keeps the TypeScript code written by the developer separate from the JavaScript code executed by the runtime.
  2. The TypeScript tools are added to a project using the standard JavaScript package manager, NPM, or one of its competitors.
  3. The TypeScript compiler processes the TypeScript files in the project and generates pure JavaScript files.
  4. The tsconfig.json file is used to configure the way the compiler generates JavaScript files.
  5. The TypeScript compiler can be used in watch mode, where TypeScript files are compiled when change is detected, but a third-party package, such as tsc-watch, is required to automatically execute the generated JavaScript files.
  6. The TypeScript compiler can generate code that conforms to different versions of the JavaScript language specification.
  7. The TypeScript compiler can generate code that uses different JavaScript module formats and has support for using the same configuration settings as Node.js to determine which format is used.

Tools that are oftern used to support TypeScript development
  1. The Node.js debugger is a useful way to inspect the state of applications as they are executed,
  2. The linter helps avoid common coding errors that are not detected by the compiler but that cause problems nonetheless,
  3. The unit test framework is used to confirm that code behaves as expected,

TypeScript can be debugged using the integrated debugger included in Visual Studio Code or using the debugger integrated into Node.js (Learn at 02 January 2023)

  1. Breakpoints can be created using the code editor or with the debugger keyword.
  2. The TypeScript linter checks TypeScript code for common problems.
  3. TypeScript relies on third-party frameworks, such as Jest, for unit testing.

Understanding static types (Learn at 03 January 2023)

  1. Restricting the range of types that can be as signed to variables or used in operations
  2. Relying on the compiler to infer types
  3. Using any, never, and unknown types to broaden or restrict the range of values
  4. Creating type unions that combine multiple types,
  5. Using type assertions and type guards to narrow types
  6. Controlling how the JavaScript null and undefined values can be used


Dukung Saya supaya tetap menulis artikel-artikel yang baik, membayar sewa domain, dan server untuk blog ini. Caranya dengan donasi cendol via Trakteer.id.


No image

Fadly Dzil Jalal

PHP, Yii2 Framework, Laravel, Java, Java Swing, Hibernate, Javascript, Angular, React, MySQL, MongoDB


Dapatkan USD 200 untuk develop aplikasimu di DigitalOcean DigitalOcean Referral Badge