Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Support? #26

Closed
eyedean opened this issue Dec 13, 2019 · 7 comments · Fixed by #38
Closed

Typescript Support? #26

eyedean opened this issue Dec 13, 2019 · 7 comments · Fixed by #38
Assignees
Labels
types TypeScript type definitions
Milestone

Comments

@eyedean
Copy link

eyedean commented Dec 13, 2019

@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.

@eyedean eyedean added the feature New functionality or improvement label Dec 13, 2019
@LorhanSohaky
Copy link

Any news?

@hueniverse
Copy link
Contributor

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.

@hueniverse hueniverse self-assigned this Jun 15, 2020
@pleytonsoftware
Copy link

pleytonsoftware commented Jun 15, 2020

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
Copy link

jweyrich commented Mar 5, 2021

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.

@hueniverse hueniverse reopened this Mar 5, 2021
@hueniverse hueniverse added types TypeScript type definitions and removed feature New functionality or improvement labels Mar 5, 2021
@ThiagoFelippi
Copy link

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
Copy link
Contributor

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types TypeScript type definitions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants