TypeScript: JavaScript With Syntax For Types.
Maybe your like
Apply types to your JavaScript project incrementally, each step improves editor support and improves your codebase.
Let's take this incorrect JavaScript code, and see how TypeScript can catch mistakes in your editor.
jsfunctioncompact(arr) {if (orr.length > 10)returnarr.trim(0, 10)returnarr}No editor warnings in JavaScript filesThis code crashes at runtime!
JavaScript file
js// @ts-check functioncompact(arr) {if (orr.length > 10)Cannot find name 'orr'.2304Cannot find name 'orr'.returnarr.trim(0, 10)returnarr}Adding this to a JS file shows errors in your editor
the param is arr, not orr!
JavaScript with TS Check
js// @ts-check /** @param{any[]}arr */functioncompact(arr) {if (arr.length > 10)returnarr.trim(0, 10)Property 'trim' does not exist on type 'any[]'.2339Property 'trim' does not exist on type 'any[]'.returnarr }Using JSDoc to give type information
Now TS has found a bad call. Arrays have slice, not trim.
JavaScript with JSDoc
tsfunctioncompact(arr: string[]) {if (arr.length > 10)returnarr.slice(0, 10)returnarr}TypeScript adds natural syntax for providing types
TypeScript file
Tag » What Is A Ts File
-
How To Play TS Files On Windows 10/8/7 And Mac - Movavi
-
TS File Extension - What Is A .ts File And How Do I Open It?
-
TS File (What It Is & How To Open One) - Lifewire
-
TS File Format - Video Transport Stream File
-
.ts Extension: What Is TS File Format & How To Open TS Video Files
-
What Is .TS File? - Quora
-
TS File - What Is It And How Do I Open It?
-
Why Does Angular 2 Use The .ts File Extension? - Stack Overflow
-
What Is A “.d.ts” File In TypeScript? | By Ohans Emmanuel | Medium
-
TS File Extension - What Is It? How To Open A TS File?
-
TS File Extension - What Is It And How To Open TS Format - Review
-
TS File Extension - What Is .ts And How To Open? - ReviverSoft
-
TS File: What Is TS File & How To Play & Convert TS Files
-
What Are TS Files? - Technipages