Skip to content

Instantly share code, notes, and snippets.

@yukikim
Created November 16, 2024 09:19
Show Gist options
  • Save yukikim/8c6456ae5d65783ba47e29716b14b182 to your computer and use it in GitHub Desktop.
Save yukikim/8c6456ae5d65783ba47e29716b14b182 to your computer and use it in GitHub Desktop.
Typescript mapの型など

マップ型を設定する3つの方法

type Things = Map<string, ThingValue>;

interface ThingValue {
  label: string;
  count: number;
}

const things1: Things = new Map();
const things2 = new Map<string, ThingValue>();

// not recommended
const mapFactory = () => new Map<string, ThingValue>();
const things3 = mapFactory();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment