Blog
  • タグ: エバーグリーン

    • 森ノートレベル4
    • 木ノートレベル3
  • 目次

    • ジャーナル
    • ノード
    • 文献
    • ウィキ
    • エリア
  • ブログへ

© Mikoshi Vault Copyright 2026. All rights reserved.

Naver ブログ編集
公開: 2022-07-29

TypeScript構文のためのSuar Syntax

条件付きプロパティ

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

プロパティの存在確認

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

分割代入プロパティ

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

key,valueイテレーター

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

optional(関数を含む)

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

filter プリミティブ型

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)]

型チェック

Array.isArray()

?? または ||

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

配列ユーティリティ

[].some
[].every


トピック: Typescript
ソース: リンク
カテゴリ: スクラップ/記事

Previousparaを分類する
Nextparaのprogressiveノート整理法