Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

as-typed

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

as-typed - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

67

index.d.ts

@@ -23,20 +23,4 @@ declare namespace AsTypedInternal {

type TypeName<T> = T extends null
? "null"
: T extends string
? "string"
: T extends any[]
? "array"
: T extends number
? "number" | "integer"
: T extends boolean
? "boolean"
: "object";
interface WithID {
$id: string;
}
type SchemaDeclaration<Type> = SchemaBase & {
type: TypeName<Type>;
type: Type;
$id?: string;

@@ -57,3 +41,3 @@ };

type NumberSchema = SchemaDeclaration<number> & {
type NumberSchema = SchemaDeclaration<"number" | "integer"> & {
multipleOf?: number;

@@ -66,3 +50,3 @@ minimun?: number;

type StringSchema = SchemaDeclaration<string> & {
type StringSchema = SchemaDeclaration<"string"> & {
pattern?: RegExp;

@@ -84,8 +68,4 @@ maxLength?: number;

type BoolSchema = SchemaDeclaration<boolean>;
type BoolSchema = SchemaDeclaration<"boolean">;
type NullSchema = SchemaDeclaration<null>;
type LeafSchema = NumberSchema | StringSchema | BoolSchema | NullSchema;
type ObjectSchema<

@@ -95,3 +75,3 @@ Props,

AdditionalProps extends SchemaBase | null = null
> = SchemaDeclaration<{}> & {
> = SchemaDeclaration<"object"> & {
required?: ReqProps;

@@ -133,3 +113,3 @@ properties?: Props;

type ArraySchemaBase = SchemaDeclaration<any[]> & {
type ArraySchemaBase = SchemaDeclaration<"array"> & {
maxItems?: number;

@@ -210,4 +190,2 @@ minItems?: number;

// This is very crude
type ResolveNot<ValueType> =

@@ -217,3 +195,3 @@ // TODO: allow Not() for array/object types of specific schemas. Not easy.

| any[]
| (ValueType extends NullSchema ? never : null)
| (ValueType extends SchemaDeclaration<"null"> ? never : null)
| (ValueType extends NumberSchema ? never : number)

@@ -227,11 +205,11 @@ | (ValueType extends StringSchema ? never : string)

? ResolveRecursiveInternal<Omit<SchemaType, "nullable">> | null
: SchemaType extends SchemaDeclaration<null>
: SchemaType extends SchemaDeclaration<"null">
? null
: SchemaType extends ConstSchema<infer Value>
? Value
: SchemaType extends SchemaDeclaration<string>
: SchemaType extends SchemaDeclaration<"string">
? string
: SchemaType extends SchemaDeclaration<boolean>
: SchemaType extends SchemaDeclaration<"boolean">
? boolean
: SchemaType extends SchemaDeclaration<number>
: SchemaType extends SchemaDeclaration<"number" | "integer">
? number

@@ -316,3 +294,3 @@ : SchemaType extends TupleSchema<infer TupleType, infer Additional>

Definitions extends DefinitionsBase
> = SchemaDeclaration<any[]> & {
> = SchemaDeclaration<"array"> & {
items: ResolveRefs<RootSchema, ValueType, Definitions>;

@@ -326,3 +304,3 @@ };

Definitions extends DefinitionsBase
> = SchemaDeclaration<any[]> & {
> = SchemaDeclaration<"array"> & {
items: ResolveRefs<RootSchema, Tuple, Definitions>;

@@ -412,17 +390,16 @@ additionalItems: ResolveRefs<RootSchema, Additional, Definitions>;

type DeepUnReadonly<T> = T extends
| string
| number
| boolean
| undefined
| null
? T
: DeepUnReadonlyObject<T>;
type DeepUnReadonly<T> = T extends object ? DeepUnReadonlyObject<T> : T;
type DeepUnReadonlyObject<T> = {
-readonly [P in keyof T]: DeepUnReadonly<T[P]>;
};
type ExpandRecursively<T> = T extends object
? T extends infer O
? { [K in keyof O]: ExpandRecursively<O[K]> }
: never
: T;
}
export type AsTyped<Schema> = AsTypedInternal.ResolveRootSchema<
AsTypedInternal.DeepUnReadonly<Schema>
export type AsTyped<Schema> = AsTypedInternal.ExpandRecursively<
AsTypedInternal.ResolveRootSchema<AsTypedInternal.DeepUnReadonly<Schema>>
>;
{
"name": "as-typed",
"version": "1.1.2",
"version": "1.1.3",
"description": "Static TypeScript types from a literal JSONSchema type",

@@ -5,0 +5,0 @@ "types": "index.d.ts",

@@ -111,3 +111,3 @@ import { AsTyped } from "./index";

}>,
_ as { a: number } & { b?: string }
_ as { a: number; b?: string }
);

@@ -114,0 +114,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc