{"id":21855490,"url":"https://github.com/wix-incubator/as-typed","last_synced_at":"2025-07-10T00:02:42.874Z","repository":{"id":52481880,"uuid":"160940552","full_name":"wix-incubator/as-typed","owner":"wix-incubator","description":"Ambient mapping from JSON schema to typescript","archived":false,"fork":false,"pushed_at":"2021-02-05T08:56:29.000Z","size":15,"stargazers_count":100,"open_issues_count":2,"forks_count":9,"subscribers_count":70,"default_branch":"master","last_synced_at":"2025-06-27T07:43:50.860Z","etag":null,"topics":["json-schema","types","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wix-incubator.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-08T13:09:38.000Z","updated_at":"2025-06-05T21:49:11.000Z","dependencies_parsed_at":"2022-09-11T00:51:21.620Z","dependency_job_id":null,"html_url":"https://github.com/wix-incubator/as-typed","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wix-incubator/as-typed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fas-typed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fas-typed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fas-typed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fas-typed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wix-incubator","download_url":"https://codeload.github.com/wix-incubator/as-typed/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wix-incubator%2Fas-typed/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264229194,"owners_count":23576235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json-schema","types","typescript"],"created_at":"2024-11-28T02:15:59.240Z","updated_at":"2025-07-10T00:02:42.688Z","avatar_url":"https://github.com/wix-incubator.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# as-typed\nAmbient mapping from JSON schema to typescript, without transpilation.\nUse JSON schemas as a first-class citizen in Typescript.\n\n## Overview\nThere are many tools that convert between Typescript and JSON schema. Howewever, all of them do that with a transpilation step.\nAmbison uses the deep inference options in typescript 3 to infer the types directly from the JSON schema.\n\nThis is not a runtime library - it contains only a single generic type, AsTyped.\nAsTyped can take any Json schema and AsTypeds it to a typescript type.\n\n\n## Example Usage\nAs-typed is ambient only. To use, simply use the JSON schema as a **type** passed to the `AsTyped` generic type instead of as a value.\nFor example:\n`AsTyped\u003c{type: 'string'}\u003e` will resolve to the typescript type `string`, and `AsTyped\u003c{type: 'object' properties: {foo: {type: 'string'}}}\u003e` will resolve to `{foo: string}` in typescript.\n\n\n## Conversion Details\nEvery JSON schema type casts to a particular typescript type, as far as possible by language limitations.\nThe following is a table of how JSON schema types translate to Typescript types with asTyped\n\n### Primitive types\n* `AsTyped\u003c{type: 'string'}\u003e` === `string`\n* `AsTyped\u003c{type: 'number'}\u003e` === `number`\n* `AsTyped\u003c{type: 'boolean'}\u003e` === `boolean`\n* `AsTyped\u003c{type: 'null'}\u003e` === `null`\n* `AsTyped\u003c{type: 'undefined'}\u003e` === `undefined`\n\n#### Limitations\n* Patterns are not supported. \n  There is no regex validation in typescript\n  [Typescript issue 6579](https://github.com/Microsoft/TypeScript/issues/6579)\n\n* Value validation (min, max etc) is not supported\n  Typescript is not meant for value checking (at least currently).\n\n### Defined objects\n* `AsTyped\u003c{type: 'object', properties: {foo: {type: 'number'}}\u003e` === `{foo?: number}`\n\n#### with required properties\n* `AsTyped\u003c{type: 'object', properties: {foo: {type: 'number'}, bar: {type: 'string}, required: ['foo']}\u003e` === `{foo: number, bar?: string}`\n\n#### objects with a specific value type\n`AsTyped\u003c{type: 'array', items: [{type: 'number'}, {type: 'string'}], additionalItems: {type: 'boolean'}}\u003e` === `[number, string, ...boolean[]]`\n\n### Recursive objects and arrays\n* `AsTyped\u003c{type: 'array', items: {type: 'array', items: {type: 'string'}}}\u003e` === `string[][]`\n* `AsTyped\u003c{type: 'object', properties: {arr: {type: 'array', items: {type: 'object', additionalProperties: {type: 'string'}}}}}` === `{arr: {[name: string]: string}[]}`\n\n### Simple array\n* `AsTyped\u003c{type: 'array', items: {type: 'string`}}\u003e` === `string[]`\n\n### Tuple\n* `AsTyped\u003c{type: 'array', items: [{type: 'string'}, {type: 'number'}]}\u003e` === `[string, number]`\n\n#### Limitations\nDue to typescript's missing variadic features, the max number of items in a tuple needs to be hardcoded, currently to 10.\n[Typescript issue 5453](https://github.com/Microsoft/TypeScript/issues/5453)\n\n### Tuple with additional items\n* `AsTyped\u003c{type: 'array', items: [{type: 'string'}, {type: 'number'}], additionalItems: {type: 'string'}}}\u003e` === `[string, number, ...string[]]`\n\n### Recursive reference by $id\n#### Simple references:\n* `AsTyped\u003c{definitions: {foo: {$id: 'foo', type: 'number'}}, $ref: 'foo'}\u003e` === `number`\n\n#### Deep references:\n* `AsTyped\u003c{definitions: {str1: {$id: 'str1', $ref: 'str2'}, str2: {$id: 'str2', type: 'string'}}, $ref: 'str1'}\u003e` === `string`\n\n#### Limitations\nReference by URL ('#/definitions/foo', 'other.json/foo') are not supported.\nTypescript doesn't allow inference by partial strings\n[Typescript Issue 12754](https://github.com/Microsoft/TypeScript/issues/12754)\n\n### not\n`Not` works mainly on primitive types, e.g. `AsTyped\u003c{not: {type: 'string'}}\u003e` will resolve to `number | object | any[] | boolean`\n\n### oneOf\n* `AsTyped\u003c{oneOf: [{type: 'string'}, {type: 'number'}]}\u003e` === `string | number`\n\nCurrently doesn't work as expected, and resolves the same as anyOf.\nSee [Typescript issue 20863](https://github.com/Microsoft/TypeScript/issues/20863)\n\n### allOf\n* `AsTyped\u003c{allOf: [{type: 'object', properties: {a: {type: 'number'}}}, {type: 'object', properties: {b: {type: 'string'}}}]}\u003e` === `{a?: number, b?: string}`\n\n### anyOf\n* `AsTyped\u003c{allOf: [{type: 'object', properties: {a: {type: 'number'}}}, {type: 'object', properties: {b: {type: 'string'}}, required: ['b']}]}\u003e` === `{a?: number, b: string} | {a?: number} | {b: string}`\n\n### If/Then/Else\n`If/Then/Else` acts exactly like `{oneOf: [{allOf: [If, Then]}, Else]}`. It's strange to have this sugar in the schema which doesn't reduce the verbosity.\nCurrently doesn't work as expected, for the same reasons as oneOf. Resolves to `(If \u0026 Then) | Else`, which is not an accurate translation.\nSee [Typescript issue 20863](https://github.com/Microsoft/TypeScript/issues/20863)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwix-incubator%2Fas-typed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwix-incubator%2Fas-typed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwix-incubator%2Fas-typed/lists"}