技術

TypeScriptで連想配列の型定義をする

投稿日:

TypeScriptを書いているときに、毎回調べていたので簡単にまとめました。

// 連想配列
let list1: { str: string; flag: boolean } = {
    str: 'string',
    flag: true
};

// 配列内連想配列
let list2: { key: string; index: boolean }[] = [
    {
      key: 'string',
      index: true
    },
    {
      key: 'hogehoge',
      index: false
    }
];

-技術

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

関連記事

no image

CSSのpositionで要素を真ん中寄せにする(JS不要)

positionを使って要素を真ん中寄せにする時は、transform: tra …

no image

【ionic】Androidビルド失敗!Multiple dex files define

どうも、中田です。 久しぶりにionicでビルドしたらAndroidビルドに失敗 …

no image

【ionic】view-titleが更新できない!!

どうも中田です。 ionicのview-titleを動的に変えるってパターンはし …

[AWS S3] This XML file does not appear to have any style information associated with it. The document tree is shown below.

はじめまして。田中です。 AWSを触りはじめてから1ヶ月ちょっと。七転び八起きな …

no image

[Angular]APIから画像を取得して表示する

こんばんは アプリケーションを作っていてフロント側で画像を出すときって ストレー …