TypeScript (1) Type declaration, type inference, union type, interface, function, type assertion, type alias, enumeration

Table of Contents (1) Introduction 1.The difference between JavaScript and TypeScript 2. Advantages of TypeScript (2) Used in vue3 project (3) Type declaration 1.Basic data types (1)string (2) number (3)boolean (4)null and undefined 2. Reference data type (1)Array array (2) Tuple tuple (3)Object object 3.any and void types (1)any (2)void 4. Use typeof to determine […]

Can JSDoc really replace TypeScript?

In the past few months, everyone must have heard the news: Svelte deprecates TypeScript and uses JSDoc instead. We know that TypeScript is used to add types to JS, which can implement type hints and compile-time type checking. Can JSDoc accomplish the same function? Why did Svelte deprecate TS? Let’s not answer this question in […]

Implement multi-part upload, resume upload, and instant upload (JS+NodeJS) (TypeScript)

1. Introduction and effects Uploading files is a very common operation, but when the file is large, the upload will take a very long time, and the upload operation will be uncertain. If the connection is accidentally disconnected, the file It will need to be uploaded again, resulting in wasting time and network resources. Therefore, […]

Can JSDoc really replace TypeScript?

In the past few months, everyone must have heard the news: Svelte deprecates TypeScript and uses JSDoc instead. We know that TypeScript is used to add types to JS, which can implement type hints and compile-time type checking. Can JSDoc accomplish the same function? Why did Svelte deprecate TS? Let’s not answer this question in […]

Can JSDoc really replace TypeScript?

In the past few months, everyone must have heard the news: Svelte deprecates TypeScript and uses JSDoc instead. We know that TypeScript is used to add types to JS, which can implement type hints and compile-time type checking. Can JSDoc accomplish the same function? Why did Svelte deprecate TS? Let’s not answer this question in […]

Type assertions in TypeScript

1. Introduction to type assertion That is, for values without type declaration, sometimes when ts type inference, the inference result is incorrect, so ts provides a type assertion method to tell the compiler what type the value here is. , and once ts discovers that there is a type assertion, it will no longer perform […]

Type tools in TypeScript

Type tools They are some built-in tools provided by ts to process various types more conveniently and generate new types, which can be used directly. That is, operations on types. 1. String type tool ts has four built-in string type tools, which are specially used to operate string types. These four tool types are defined […]

TypeScript’s type system

Type system 1. What is the type? A type refers to a set of values with the same characteristics. If two values have some common characteristics, they can be said to belong to the same type. Once the type of a value is determined, it means that the value has all the characteristics of that […]

Objects in TypeScript

1. Introduction Use curly braces to represent objects, and declare the type of each property and method inside the curly braces. const obj:{<!– –> x:number; y:number; } = {<!– –> x: 1, y: 1 }; The attribute type can end with a semicolon or a comma. After the last attribute, you can write a semicolon, […]

Modules in TypeScript

1. Introduction to ts module If a file contains import or export statements, it is a module. Correspondingly, if the file does not contain export statements, it is a global script file. The module itself is a scope and does not belong to the global scope. The variables, functions, and classes inside the module are […]