jsonpointer

TypeScript type definition for an object property path [duplicate]

无人久伴 提交于 2021-02-07 04:27:11
问题 This question already has answers here : Typescript: deep keyof of a nested object (2 answers) Closed 1 year ago . Is it possible to type an array of strings in such a way that the array can only be a valid property path in a given object? The type definition should work for all deeply nested objects. Example: const object1 = { someProperty: true }; const object2 = { nestedObject: object1, anotherProperty: 2 }; type PropertyPath<Type extends object> = [keyof Type, ...Array<string>]; // <--

Use object property keys as enum in JSON schema

坚强是说给别人听的谎言 提交于 2019-12-07 11:14:09
问题 I'm trying to validate a JSON file using JSON Schema, in order to find cases of "broken references". Essentially my file consists of items and groups, with each item belonging to a single group referenced by the groups property key, like so: { "items": { "banana": { "name": "Banana", "group": "fruits" }, "apple": { "name": "Apple", "group": "fruits" }, "carrot": { "name": "Carrot", "group": "vegetables" }, "potato": { "name": "Potato", "group": "vegetables" }, "cheese": { "name": "Cheese",

Use object property keys as enum in JSON schema

落爺英雄遲暮 提交于 2019-12-05 15:53:59
I'm trying to validate a JSON file using JSON Schema, in order to find cases of "broken references". Essentially my file consists of items and groups, with each item belonging to a single group referenced by the groups property key, like so: { "items": { "banana": { "name": "Banana", "group": "fruits" }, "apple": { "name": "Apple", "group": "fruits" }, "carrot": { "name": "Carrot", "group": "vegetables" }, "potato": { "name": "Potato", "group": "vegetables" }, "cheese": { "name": "Cheese", "group": "dairy" } }, "groups": { "fruits": { "name": "Fruits" }, "vegetables": { "name": "Vegetables" }