📗
Notes
  • Introduction
  • Files
  • Android
    • Http
      • Http基础
      • Okhttp理解
    • Jetpack
      • Notes
  • Java ways
    • 101
      • Basis
        • Index
        • Front
          • Angular
            • Angular start 01
            • Angular start 02
          • Typescript
            • Index
            • Ts 01
        • Java
          • Concurrency
          • Frameworks
            • Jdbc与连接池
            • Rxjava基础
            • Spring框架基础
          • Sugar&skill
        • Tool
          • Docker
            • Docker basis
            • Kubernetes play
          • Git
            • Git basic
          • Vim
            • Vim advance
      • Cs
        • Imp
          • Lru
          • Index
    • Snippets
      • Jpa和spring系列注解表
      • Java与oracle数据库各种操作
      • Maven初始化template
      • Nginx配置
      • Nginx反代后配置自动ssl续签
      • 终端033颜色
    • Ways
      • Java ways 01
      • Interview
        • Question
        • Requirements
      • Leetcode101
        • Acwing
          • Index
          • 背包问题
        • Explores
        • Solutions
          • Algorithms
            • Index
          • Concurrency
            • Index
          • Shell
            • Index
          • Sql
            • Index
  • Leecode
    • 牛客
      • 剑指offer
  • Play
    • Youtube离线下载
  • Python basic notes
    • Python days
Powered by GitBook
On this page
  • TypeScript Start 01
  • Basic
  • Init
  • Core Types
  • 一些疑问与探索

Was this helpful?

  1. Java ways
  2. 101
  3. Basis
  4. Front
  5. Typescript

Ts 01

PreviousIndexNextJava

Last updated 4 years ago

Was this helpful?

   Author: Gentleman.Hu
   Create Time: 2020-11-08 22:29:31
   Modified by: Gentleman.Hu
   Modified time: 2020-11-10 23:57:02
   Email: justfeelingme@gmail.com
   Home: https://crushing.xyz
   Description: TypeScript Start

TypeScript Start 01

Basic

Init

  • npm init

  • npm install --save-dev lite-server

  • npm start

Core Types

  • ts中静态类型,可在编译期检查到类型不匹配错误

  • js动态类型,随意转换

function add(n1: number, n2: number){
  if(typeof n1 !== 'number' || typeof n2 !== 'number'){
    throw new Error('Incorrect input!');
  }
  return n1 + n2;
}

const number1 = '5'
const number2 = 2.5;

const result = add(number1,number2);
console.log(result);

如上代码,在ts中,写代码期间(编译前期间)就可被编译器检查到类型不匹配.

一些疑问与探索

  • html标签中<script src=" " defer>的defer啥意思?

Definition and Usage
The defer attribute is a boolean attribute.

When present, it specifies that the script is executed when the page has finished parsing.

Note: The defer attribute is only for external scripts (should only be used if the src attribute is present).

Note: There are several ways an external script can be executed:

If async is present: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing)
If async is not present and defer is present: The script is executed when the page has finished parsing
If neither async or defer is present: The script is fetched and executed immediately, before the browser continues parsing the page
  • --save-dev和--save区别

There are (at least) two types of package dependencies you can indicate in your package.json files:

Those packages that are required in order to use your module are listed under the "dependencies" property. Using npm you can add those dependencies to your package.json file this way:

npm install --save packageName
Those packages required in order to help develop your module are listed under the "devDependencies" property. These packages are not necessary for others to use the module, but if they want to help develop the module, these packages will be needed. Using npm you can add those devDependencies to your package.json file this way:

npm install --save-dev packageName

defer_in_html
difference__
https://www.youtube.com/watch?v=BwuLxPH8IDs