0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JSONの型定義を宣言する(メモ)

Last updated at Posted at 2025-02-03

定義

ないなら作る

// JSON.d.ts

export type JSON = JsonPrimitive | JsonArray | JsonObject;

export type JsonObject = {
  [key: string]: JSON;
};

export type JsonArray = JsonPrimitive[] | JsonObject[] | JsonArray[];

export type JsonPrimitive = string | number | boolean | null;

Usage

import type { JSON } from "./JSON.d"

const json: JSON = {
    "文字": "abc",
    
    "数値": 123,
    
    "真偽": false,

    "NULL": null,

    "配列": [
        "a", "b", "c",
        
        1, 2, 3,
        
        true, false,
        
        ["a", "b", "c"],
        
        [1, 2, 3],
        
        [true, false],
        
        [null],

        {
            "プロパティ": "",
            
            "配列": [
                // ... (略) ...
            ]
        }
        // ... (略) ...
    ],
    
    "物体": {
        "プロパティ": "",
        
        "配列": [
            // ... (略) ...
        ]
        
        "プロパティ": {
            // ... (略) ...
        }
    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?