hapijs / joi-date

Joi extensions for dates
Other
83 stars 25 forks source link

Typescript Support? #26

Closed eyedean closed 3 years ago

eyedean commented 4 years ago

@hapi/joi has a .d.ts type definition for Typescript at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/hapi__joi/index.d.ts

I was wondering if there is a .d.ts support for joi-date as well. I have a relatively big project built in Typescript and heavily using Joi, so without a .d.ts file, I cannot use joi-date.

(Sorry that I am removing the template for creating issues. I don't think node version or other information apply to this.)

Thanks.

LorhanSohaky commented 4 years ago

Any news?

hueniverse commented 4 years ago

The template contains other information including under which support plan this is opened. Next time please just fill in the template as asked.

There is no official TS support for joi as of yet including this module and I don't have any idea when it will be available.

pleytonsoftware commented 4 years ago

Hi. Just for everyone that comes to here to know about the support in Typescript.

If there is any official support or not, I am not sure but I am leaving this over here for anyone that needs the declaration file.

declare module '@hapi/joi-date' {
    import { Extension } from '@hapi/joi';
    const JoiDate: Extension;
    export default JoiDate;
}

I hope it helps. :)

jweyrich commented 3 years ago

The following should suffice to make the compiler happy about .format():

declare module "joi" {
  interface DateSchema {
    format(format: string): this;
  }
}

@hueniverse Any chances to get this definition into the repo? Maybe put it in a globals.d.ts.

ThiagoFelippi commented 3 years ago

Alternatively you can add just:

import * as Extension from "@joi/date";
import * as joi from "joi";

const joiDate = joi.extend(Extension);

This will not add types but will run code correctly

hueniverse commented 3 years ago

If someone submits a PR that copies the definitions from DT here and makes sure they are up to date, I'll review. Need to add a test file with the lab -Y flag similar to how other sideway modules are set up. Type tests must include at least one expected error.

kanongil commented 3 years ago

@hueniverse There does not appear to be any existing definitions in DT.