TCMiranda / joi-extract-type

Provides native type extraction from Joi schemas for Typescript
MIT License
152 stars 27 forks source link

What's a consistent and working set of dependencies for Typescript 4? #43

Open helgridly opened 3 years ago

helgridly commented 3 years ago

I've been struggling to find a set of dependencies that work smoothly together. Here's what I've tried so far:

@hapi/joi@17 & joi-extract-type@15.0.2

Suggestion from this page. Gives me:

error TS2315: Type 'extractType' is not generic.

@hapi/joi@17 & joi-extract-type@15.0.2 & @types/hapi__joi

error TS2694: Namespace 'Joi' has no exported member 'extractType'.

@hapi/joi@15.1.1 & joi-extract-type@15.0.2

Based on comments that joi-extract-type doesn't support 16+ yet.

error TS2315: Type 'extractType' is not generic.

@hapi/joi@15.1.1 & joi-extract-type@15.0.2 & @types/hapi__joi

error TS2694: Namespace 'Joi' has no exported member 'extractType'.

I've also tried joi@17.3.0 & joi-extract-type@15.0.2 per this comment but my TS novice-ness couldn't figure out where to put the provided joi.d.ts and how to set up typeRoots for it to be visible.

If someone can post a set of dependencies which work together I'd be super grateful.

lonewarrior556 commented 3 years ago
{
  "dependencies": {
    "@hapi/joi": "15.1.1",
    "joi-extract-type": "15.0.2",
    "@types/hapi__joi": "15.0.4"
  }
}
helgridly commented 3 years ago

Thank you! Unfortunately, that still gives me:

error TS2694: Namespace '"/path/to/node_modules/@types/hapi__joi/index"' has no exported member 'extractType'.
lonewarrior556 commented 3 years ago

also I have

  "typescript": "3.8.3"

If that's not it, The way you are implementing it must be the issue. Make sure you have

import joi from '@hapi/joi';
import 'joi-extract-type';

whereever you use joi

helgridly commented 3 years ago

You're right - I'd been flipping back and forth between using joi-extract-type and not, and in the last case hadn't imported it at all 🤦 Thank you!

This works for me:

    "typescript": "3.8.3",
    "@hapi/joi": "15.1.1",
    "joi-extract-type": "15.0.2",
    "@types/hapi__joi": "15.0.4"

The typescript 3.8 dependency is indeed important - running via ts-node works for me on TS 4 but gave me the known circular dependency error when I ran tsc.

@TCMiranda I'm happy to make a PR to the readme to document this, if you'd like.

domdomegg commented 3 years ago

This set seems to work for me:

    "@hapi/joi": "17.1.1",
    "@types/hapi__joi": "15.0.4",
    "typescript": "4.1.3",
    "joi-extract-type": "15.0.8",