Blog
  • Thẻ: Evergreen

    • Ghi chú rừngCấp 4
    • Ghi chú câyCấp 3
  • Mục lục

    • Nhật ký
    • Nút
    • Tài liệu
    • Wiki
    • Lĩnh vực
  • Đến Blog

© Mikoshi Vault Copyright 2026. All rights reserved.

Blog NaverSửa
Đã xuất bản: 2022-07-29

Suar Syntax cho ngữ pháp TypeScript

Thuộc tính có điều kiện

const person = {
  id: 'abx',
  ...(isVliad && { isActive: true }),
  ...((age >= 10 || isValid) && { card: true }),
}

Kiểm tra sự tồn tại của thuộc tính

const person = { id: 'abc' }
console.log('id' in person)

Thuộc tính destructuring

const productData = { id: '12', name: 'laptop' }
const { id: helloworld } = productData
console.log(helloworld, 'hello world is')

Trình lặp key,value

const data = {id:1, name: 'laptop', isSale:true}
Object.entries(data).forEach(([key,value])=>{
  console.log(`${key} and ${value}`)
})

Optional (bao gồm hàm)

const data = {id:1, name: 'laptop', isSale:true}
console.log(data?.id)
console.log(data?.hello)
data?.nameDiplay?.()

Lọc kiểu cơ bản

const fruitList = ['apple', null , 'mango']
const filteredFruit = fruitList.filter(Boolean)
const isANyFruit = fruitList.some(Boolean)

uniq

const fruitList = ['apple', 'mango', 'apple']
const uniqFruit = [...new Set(fruitList)]

Kiểm tra kiểu

Array.isArray()

?? hoặc ||

??는 앞에꺼 먼저
||는 뒤에꺼 먼저

Tiện ích mảng

[].some
[].every


Chủ đề: Typescript
Nguồn: 링크
Danh mục: Trích lược/Bài viết

PreviousPhân loại PARA
NextCách sắp xếp ghi chú progressive của para