2024.05.01 19:18 Sychamis Lotus 1 theme port to my sequencer
2024.01.11 15:16 idmitriev Schema type inference in validator type predicate
type JsonObject = { [key: string]: JsonValue }; type JsonValue = string number boolean null ArrayJsonObject; type Schema = ScalarSchema<"string"> ScalarSchema<"number"> ScalarSchema<"boolean"> ScalarSchema<"null"> ArraySchema ObjectSchema UnionSchema; type ScalarType = "string" "number" "boolean" "null"; type ScalarSchema = { type: Type; }; type ArraySchema = { type: "array"; items: Schema; }; type ObjectSchema = { type: "object"; properties: { [key: string]: Schema }; }; type UnionSchema = { oneOf: Array ; }; type Infer = SomeSchema extends ScalarSchema ? InferScalarType : SomeSchema extends ArraySchema ? InferArrayType : SomeSchema extends ObjectSchema ? InferObjectType : SomeSchema extends UnionSchema ? InferUnionType : never; type InferScalarType = SomeScalarType["type"] extends "string" ? string : SomeScalarType["type"] extends "number" ? number : SomeScalarType["type"] extends "boolean" ? boolean : SomeScalarType["type"] extends "null" ? null : never; type InferArrayType = Array< Infer >; type InferObjectType = { [key in keyof SomeObjectSchema["properties"]]: Infer< SomeObjectSchema["properties"][key] >; }; type InferUnionType = MapToInfered< SomeUnionSchema["oneOf"][number] >; type MapToInfered = UnionOfSchemas extends any ? Infer : never; function isOfSchema ( schema: SomeSchema, json: JsonValue, ): json is Infer { if ("type" in schema) { switch (schema.type) { case "string": return typeof json === "string"; case "number": return typeof json === "number"; case "boolean": return typeof json === "boolean"; case "null": return json === null; case "array": return ( Array.isArray(json) && json.every((item) => isOfSchema(schema.items, item)) ); case "object": return ( typeof json === "object" && json !== null && !Array.isArray(json) && Object.keys(schema.properties).every((key) => isOfSchema(schema.properties[key], json[key]), ) ); } } else { return schema.oneOf.some((schema) => isOfSchema(schema, json)); } }
2023.06.14 03:27 twopiecejrbuffs The nuggets won the championship and jokic was the mvp!!!
submitted by twopiecejrbuffs to u/twopiecejrbuffs [link] [comments] |
2023.06.13 22:48 aBigSportsFan r/nbacirclejerk celebrating the thousands of subscribers it gained due to the r/nba blackout
submitted by aBigSportsFan to nbacirclejerk [link] [comments] |