Gathering detailed insights and metrics for as-typed
Gathering detailed insights and metrics for as-typed
Gathering detailed insights and metrics for as-typed
Gathering detailed insights and metrics for as-typed
safefs
Stop getting EMFILE errors! Open only as many files as the operating system supports.
make-deno-edition
Automatically makes package.json projects (such as npm packages and node.js modules) compatible with Deno.
as-typed-array
Make any value an array
@winible/winible-typed
The Winible Typescript Models or `@winible/winible-typed` npm package is a project that holds all of Winible's sequelize database model declarations, sequelize client instantiation, as well as type declarations for unifying type sharing between all of our
Static TypeScript types from a literal JSONSchema type
npm install as-typed
Typescript
Module System
Node Version
NPM Version
94.8
Supply Chain
100
Quality
76.2
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
1,671,267
Last Day
1,487
Last Week
19,342
Last Month
80,616
Last Year
747,365
MIT License
43 Stars
75 Commits
2 Forks
2 Watchers
10 Branches
1 Contributors
Updated on Aug 08, 2024
Latest Version
1.3.2
Package Id
as-typed@1.3.2
Unpacked Size
13.77 kB
Size
4.35 kB
File Count
5
NPM Version
6.14.15
Node Version
14.18.1
Cumulative downloads
Total Downloads
Last Day
52.2%
1,487
Compared to previous day
Last Week
-5.8%
19,342
Compared to previous week
Last Month
10.9%
80,616
Compared to previous month
Last Year
48.4%
747,365
Compared to previous year
as-typed
Type magic to convert a JSON Schema literal into the proper TypeScript type representation, all without additional build steps. This module has no runtime functionality by itself. It exposes a single AsTyped
type which takes a valid JSON Schema and outputs the equivalent type for it. With this you can get type safety at runtime and validate your values at runtime writing types just once. Great for JSON integrations and data serialization.
This is forked from https://github.com/wix-incubator/as-typed fixing many bugs, modernizing and introducing support for more types thanks to newer TypeScript features.
npm install --save-dev as-typed
1import { AsTyped } from "as-typed"; 2 3const schema = { 4 title: "Example Schema", 5 type: "object", 6 required: ["firstName", "age", "hairColor"], 7 properties: { 8 firstName: { 9 type: "string" 10 }, 11 lastName: { 12 type: "string" 13 }, 14 age: { 15 type: "integer", 16 minimum: 0 17 }, 18 hairColor: { 19 enum: ["black", "brown", "blue"], 20 type: "string" 21 } 22 } 23} as const; // <<< "as const" is important to preserve literal type 24 25type SchemaT = AsTyped<typeof schema>; 26/* 27 type SchemaT = { 28 firstName: string; 29 age: number; 30 hairColor: "black" | "brown" | "blue"; 31 lastName?: string; 32 }; 33*/
1type Str = AsTyped<{ type: "string" }>; // string 2type Num = AsTyped<{ type: "number" }>; // number 3type Int = AsTyped<{ type: "integer" }>; // number 4type Bool = AsTyped<{ type: "boolean" }>; // boolean 5type Null = AsTyped<{ type: "null" }>; // null 6 7type ConstStr = AsTyped<{ type: "string"; const: "Hello" }>; // "Hello" 8type ConstNum = AsTyped<{ type: "integer"; const: 4 }>; // 4 9type Enum = AsTyped<{ 10 type: "string"; 11 enum: ["First", "Second", "Third"]; 12}>; // "First" | "Second" | "Third" 13 14type Nullable1 = AsTyped<{ type: ["string", "null"] }>; // string | null 15type Nullable2 = AsTyped<{ type: "string"; nullable: true }>; // string | null
1type Obj1 = AsTyped<{ 2 type: "object"; 3 properties: { 4 foo: { type: "number" }; 5 }; 6}>; // { foo?: number } 7 8type Obj2 = AsTyped<{ 9 type: "object"; 10 properties: { 11 foo: { type: "number" }; 12 bar: { type: "string" }; 13 }; 14 required: ["foo"]; 15}>; // { foo: number, bar?: string } 16 17type Obj3 = AsTyped<{ 18 type: "object"; 19 additionalProperties: { type: "integer" }; 20}>; // Record<string, number>
1type List1 = AsTyped<{ 2 type: "array"; 3 items: { type: "string" }; 4}>; // string[] 5 6type List2 = AsTyped<{ 7 type: "array"; 8 items: { 9 type: "array"; 10 items: { type: "string" }; 11 }; 12}>; // string[][] 13 14type Tuple1 = AsTyped<{ 15 type: "array"; 16 items: [{ type: "string" }, { type: "number" }]; 17}>; // [string, number] 18 19type Tuple2 = AsTyped<{ 20 type: "array"; 21 items: [{ type: "number" }, { type: "string" }]; 22 additionalItems: { type: "boolean" }; 23}>; // [number, string, ...boolean[]]
1type ObjFromRefs = AsTyped<{ 2 definitions: { 3 User: { 4 $id: "userschemaid"; 5 type: "object"; 6 properties: { 7 name: { type: "string" }; 8 age: { type: "integer" }; 9 }; 10 }; 11 UserList: { 12 $id: "userlist"; 13 type: "array"; 14 items: { $ref: "userschemaid" }; 15 }; 16 }; 17 type: "object"; 18 required: ["result"]; 19 properties: { result: { $ref: "userlist" } }; 20}>; // { result: { name?: string, age?: number }[] }
1type ObjFromRefs = AsTyped<{ 2 definitions: { 3 User: { 4 type: "object"; 5 properties: { 6 name: { type: "string" }; 7 age: { type: "integer" }; 8 }; 9 }; 10 UserList: { 11 type: "array"; 12 items: { $ref: "#/definitions/User" }; 13 }; 14 }; 15 type: "object"; 16 required: ["result"]; 17 properties: { result: { $ref: "#/definitions/UserList" } }; 18}>; // { result: { name?: string, age?: number }[] }
1type Union1 = AsTyped<{ anyOf: [{ type: "string" }, { type: "number" }] }>; // string | number 2 3type Union2 = AsTyped<{ oneOf: [{ type: "string" }, { type: "number" }] }>; // string | number 4 5type Intersection1 = AsTyped<{ 6 allOf: [ 7 { type: "object"; properties: { a: { type: "number" } } }, 8 { type: "object"; properties: { b: { type: "string" } } } 9 ]; 10}>; // { a?: number, b?: string } 11 12type Intersection2 = AsTyped<{ 13 allOf: [ 14 { type: "object"; properties: { a: { type: "number" } } }, 15 { 16 oneOf: [ 17 { type: "object"; properties: { b: { type: "string" } } }, 18 { type: "object"; properties: { b: { type: "boolean" } } } 19 ]; 20 } 21 ]; 22}>; // { a?: number; b?: string } | { a?: number; b?: boolean } 23 24type Not = AsTyped<{ not: { type: "string" } }>; // number | object | any[] | boolean | null | undefined
oneOf
Currently doesn"t work as expected, and resolves the same as anyOf. See Typescript issue 20863.if
/ then
/ else
acts exactly like {oneOf: [{allOf: [If, Then]}, Else]}
. Currently doesn't work as expected, for the same reasons as oneOf. Resolves to (If & Then) | Else
, which is not an accurate translation.No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/14 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More