Kits

システム、プログラミングなど

2021-05-05から1日間の記事一覧

TypeScript の enum

TypeScript では enum型(列挙型)を 使用することが出来る。 enum のサンプルコード enum OS { Windows, Mac, Linux, } enum Maker { Dell, HP, ASUS, } interface PC { os: OS; maker: Maker; } const myPC: PC = { os: OS.Windows, maker: Maker.Dell, }

TypeScript の keyof

TypeScript では keyof でオブジェクトの キーを取り出すことが出来る。 keyof のサンプルコード type KEYS = { primary: string, secondary: string, tertiary: string } let key: keyof KEYS; key = "primary" const COUNTRIES = { primary: "USA", second…

TypeScript の typeof

TypeScript では typeof を使用して、 型を流用できる。 typeof のサンプルコード let profile1 = { name: "Mike", age: 24 }; let profile2: typeof profile1 = { name: "Ken", age: 22 }

TypeScript で Literal Types

TypeScript では Literal Types を使用して、 指定した値しか代入できないようにすることが出来る。 Literal Types のサンプルコード let country: "USA" | "China" | "India"; country = "USA";

TypeScript の UnionTypes

TypeScript では UnionTypes を使用して 複数の型を指定することが出来る。 UnionTypesのサンプルコード let val: boolean | number; val = true; val = 1; let arry: (number | string)[]; arry = [0, 1, "Hello"];

TypeScript の Intersection Types

TypeScriptではIntersection Typesを使って 型の結合することが出来る。 Intersection Types のサンプルコード type ID = { username: string; password: string; } type PROFILE = { name: string; age: number; } type USER = ID & PROFILE const user1: U…

TypeScriptでの型の指定

型の指定の例 サンプルコード let name: string = "Mike"; let age: number = "24"; let adult: boolean = true; interface ADRESS { state: string; county: string; city?: string; street: string | null; } let add: ADDRESS = { state: "California", c…

djangorestframework-simplejwt で Unauthorized

djangorestframework-simplejwt で Unauthorized の認証エラー settings.py の設定内容が誤っていたので下記の通り修正。 REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.IsAuthenticated', ], 'DEFAULT_AUTHENTICATION_C…