1.0.0 • Published 1 year ago

json-types2 v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

json-types2

JSON TypeScript Definitions

A simple typescript definition module that simplifies type checking for valid JSON objects. Useful for defining interfaces and parameter type checking.

Installation

npm install -D json-types2

Usage

import { JSONValue, JSONValidObject, JSONValidArray, JSONPrimitive, JSONValidMap, JSONValidSet } from "../json-types";

Example

import { JSONValue, JSONValidObject, JSONValidArray, JSONPrimitive, JSONValidMap, JSONValidSet } from "../json-types";

interface QueryString {
	[key: string]: JSONPrimitive | undefined;
}

interface APIResponse extends JSONValidObject {
	address: {
		house_no: number;
		street: string;
	};
	name: string;
	has_website: false;
	files: JSONValidArray;
	metadata: JSONValue;
}

function httpGet(url: string): Promise<JSONValue> {
	return requestPromise(url, {
		json: true,
	});
}
1.0.0

1 year ago