Skip to content

Commit

Permalink
refactor: make joi.meta() arguments type-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Sep 9, 2019
1 parent 3b9ba8e commit a878990
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions garden-service/src/config/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,59 @@ interface JoiPathParams {
}

// Extend the Joi module with our custom rules
export interface CustomStringSchema extends Joi.StringSchema {
gitUrl: (params: JoiGitUrlParams) => CustomStringSchema
posixPath: (params?: JoiPathParams) => CustomStringSchema
interface MetadataKeys {
internal?: boolean
deprecated?: boolean
extendable?: boolean
}

// Unfortunately we need to explicitly extend each type (just extending the AnySchema doesn't work).
declare module "@hapi/joi" {
export function string(): CustomStringSchema
export interface AnySchema {
meta(keys: MetadataKeys): this
}

export interface ArraySchema {
meta(keys: MetadataKeys): this
}

export interface AlternativesSchema {
meta(keys: MetadataKeys): this
}

export interface BinarySchema {
meta(keys: MetadataKeys): this
}

export interface BooleanSchema {
meta(keys: MetadataKeys): this
}

export interface DateSchema {
meta(keys: MetadataKeys): this
}

export interface FunctionSchema {
meta(keys: MetadataKeys): this
}

export interface NumberSchema {
meta(keys: MetadataKeys): this
}

export interface ObjectSchema {
meta(keys: MetadataKeys): this
}

export interface StringSchema {
meta(keys: MetadataKeys): this
gitUrl: (params: JoiGitUrlParams) => this
posixPath: (params?: JoiPathParams) => this
}

export interface LazySchema {
meta(keys: MetadataKeys): this
}
}

export const joi: Joi.Root = Joi.extend({
Expand Down

0 comments on commit a878990

Please sign in to comment.