From 0065fbe0b9679f9df1a8a12e546217e4e07107f3 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Fri, 1 Nov 2019 19:46:09 +0200 Subject: [PATCH] superstruct: Provides its own types (#39552) --- notNeededPackages.json | 6 ++ types/superstruct/index.d.ts | 97 -------------------------- types/superstruct/superstruct-tests.ts | 87 ----------------------- types/superstruct/tsconfig.json | 23 ------ types/superstruct/tslint.json | 1 - 5 files changed, 6 insertions(+), 208 deletions(-) delete mode 100644 types/superstruct/index.d.ts delete mode 100644 types/superstruct/superstruct-tests.ts delete mode 100644 types/superstruct/tsconfig.json delete mode 100644 types/superstruct/tslint.json diff --git a/notNeededPackages.json b/notNeededPackages.json index 8796fe7dd0..7e0b39052c 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -4320,6 +4320,12 @@ "sourceRepoURL": "https://github.com/andrewplummer/Sugar", "asOfVersion": "2.0.2" }, + { + "libraryName": "superstruct", + "typingsPackageName": "superstruct", + "sourceRepoURL": "https://github.com/ianstormtaylor/superstruct#readme", + "asOfVersion": "0.8.0" + }, { "libraryName": "survey-knockout", "typingsPackageName": "survey-knockout", diff --git a/types/superstruct/index.d.ts b/types/superstruct/index.d.ts deleted file mode 100644 index de8b89c22a..0000000000 --- a/types/superstruct/index.d.ts +++ /dev/null @@ -1,97 +0,0 @@ -// Type definitions for superstruct 0.5 -// Project: https://github.com/ianstormtaylor/superstruct#readme -// Definitions by: Edward Snare -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.5 - -export as namespace superstruct; - -export interface Config { - types?: {[type: string]: CustomType}; -} - -export type CustomType = (value: any) => boolean|string; - -export function isStruct(value: any): boolean; - -export class Kind { - constructor(name: string, type: string, validate: (value?: any, data?: any) => any[]); - name: string; - type: string; - validate: (value?: any, data?: any) => any[]; -} - -export const struct: struct; - -export interface struct { - (schema: Types, defaults?: object, options?: {}): Struct; - /** `any` structs are the equivalent of using the `struct()` function directly, providing the shorthands for commonly used notations. */ - any(data: any): Kind; - /** `dict` structs validate an object's keys and values. But, unlike `object` structs, they do not enforce a specific set of keys. */ - dict(data: [Type, Type]): Kind; - /** `enum` structs validate that a value is one of a specific set of literals. */ - enum(literals: any[]): Kind; - /** - * `function` structs will validate using the validation function provided. - * They're helpful as an escape hatch in cases when you really need to write a one-off validation, and don't want to add it to your set of known data types. - */ - function(type: (value: any, data?: any) => boolean|string|object): Kind; - /** `instance` structs validate that an object is an instance of a particular class, using the built-in instanceof operator. */ - instance(object: any): Kind; - /** - * `interface` structs validate that a value has a set of properties on it, but it does not assert anything about unspecified properties. - * This allows you to assert that a particular set of functionality exists without a strict equality check for properties. - */ - interface(properties: Types): Kind; - /** `intersection` structs validate that a value matches all of many structs. Their arguments are any other validate struct schema. */ - intersection(structs: Type[]): Kind; - /** `lazy` structs accepts a function that will return a struct. They are useful to create recursive structs. */ - lazy(structs: () => Kind): Kind; - /** `list` structs will validate that all of the elements in an array match a specific type. The elements's schema can be any valid value for a struct—string, array, object or function. */ - list(elements: Type[]): Kind; - /** `literal` structs enforces that a value matches an exact, pre-defined value, using the `===` operator. */ - literal(value: any): Kind; - /** - * `object` structs will validate that each of the properties in an object match a specific type. - * The properties's schemas can be any valid value for a struct—string, array, object or function. - */ - object(properties: Types): Kind; - /** `optional` structs validate that a value matches a specific kind of struct, or that it is `undefined`. */ - optional(type: Type): Kind; - /** - * `partial` structs are similar to `object` structs, but they only require that the specified properties exist, and they don't care about other properties on the object. - * They differ from `interface` structs in that they only return the specified properties. - */ - partial(properties: Types): Kind; - /** `scalar` structs are the lowest-level type of struct. They validate that a single scalar value matches a type, denoted by a type string. */ - scalar(value: string): Kind; - /** `tuple` structs validate that a value is a specific array tuple of values. */ - tuple(values: Type[]): Kind; - /** `union` structs validate that a value matches at least one of many structs. Their arguments are any other validate struct schema. */ - union(schemas: Type[]): Kind; -} - -export interface Struct { - (data: object): any; - /** @throws {StructError} */ - assert(value: object): any; - test(value: object): boolean; - validate(value: object): [StructError]|[undefined, any]; -} - -export interface StructError extends TypeError { - data: any; - path: string[]; - value: any; - reason: any; - type: string; - errors: StructError[]; -} - -export function superstruct(config?: Config): struct; - -export type Type = any; - -export interface Types { - [type: string]: Type; -} diff --git a/types/superstruct/superstruct-tests.ts b/types/superstruct/superstruct-tests.ts deleted file mode 100644 index ce8ab8a636..0000000000 --- a/types/superstruct/superstruct-tests.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { superstruct, isStruct, struct, StructError } from "superstruct"; - -// $ExpectType struct -let myStruct = superstruct(); - -// $ExpectType struct -myStruct = superstruct({ - types: { - id: (value: any) => typeof value === "string" && /^[a-z0-9]+$/.test(value) - } -}); - -// $ExpectError -isStruct(); - -// $ExpectType boolean -isStruct(myStruct); - -// $ExpectError -let MyOtherStruct = myStruct(); - -// $ExpectType Struct -MyOtherStruct = myStruct({ - id: 'id', - password: struct.function(value => typeof value === "string" && value.length > 5), - passwordRepeat: struct.function((value, data) => data.password && value === data.password) -}); - -const value: object = { id: "5n4r3", password: "****", passwordRepeat: "****" }; - -// $ExpectType any -MyOtherStruct(value); - -// $ExpectType any -MyOtherStruct.assert(value); - -// $ExpectType boolean -MyOtherStruct.test(value); - -// $ExpectType [StructError] | [undefined, any] -MyOtherStruct.validate(value); - -// $ExpectType Kind -struct.any("any"); -// $ExpectType Kind -struct.dict(['string', Date]); -// $ExpectType Kind -struct.enum(['one', 'two']); -// $ExpectType Kind -struct.function(value => typeof value === 'string'); -// $ExpectType Kind -struct.instance(Date); -// $ExpectType Kind -struct.interface({ - property: 'number', - method: 'function', -}); -// $ExpectType Kind -struct.intersection(['string', 'email']); -// $ExpectType Struct -const BinaryTree: any = struct({ - value: 'any', - left: struct.lazy(() => struct.optional(BinaryTree)), - right: struct.lazy(() => struct.optional(BinaryTree)), -}); -// $ExpectType Kind -struct.list(['string']); -// $ExpectType Kind -struct.literal(42); -// $ExpectType Kind -struct.object({ - id: 'number', - name: 'string', -}); -// $ExpectType Kind -struct.optional('string'); -// $ExpectType Kind -struct.partial({ - a: 'number', - b: 'number', -}); -// $ExpectType Kind -struct.scalar('string'); -// $ExpectType Kind -struct.tuple(['string', 'number', 'boolean']); -// $ExpectType Kind -struct.union(['string', 'number']); diff --git a/types/superstruct/tsconfig.json b/types/superstruct/tsconfig.json deleted file mode 100644 index 1a972f210e..0000000000 --- a/types/superstruct/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "superstruct-tests.ts" - ] -} diff --git a/types/superstruct/tslint.json b/types/superstruct/tslint.json deleted file mode 100644 index 3db14f85ea..0000000000 --- a/types/superstruct/tslint.json +++ /dev/null @@ -1 +0,0 @@ -{ "extends": "dtslint/dt.json" }