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

Import error related to types in a new project #4459

Open
dcyriller opened this issue Sep 20, 2023 · 1 comment
Open

Import error related to types in a new project #4459

dcyriller opened this issue Sep 20, 2023 · 1 comment

Comments

@dcyriller
Copy link

dcyriller commented Sep 20, 2023

context

While using the framework for the first time, I encountered a minor issue. It's not critical (in my case, I will simply install joi), but I thought you might want to be aware of it. Have a good day!

reproduction

In a new node.js project:

  • install @hapi/hapi
  • create a server.ts file with the content:
import Hapi from "@hapi/hapi";

async function init() {
    const server = Hapi.server({
        port: 3000,
        host: 'localhost'
    });

    await server.start();
    console.log('Server running on %s', server.info.uri);
};

init();
  • you get the following error:
> tsc

node_modules/@hapi/hapi/lib/types/route.d.ts:2:68 - error TS2307: Cannot find module 'joi' or its corresponding type declarations.

2 import { ObjectSchema, ValidationOptions, SchemaMap, Schema } from 'joi';
                                                                     ~~~~~

node_modules/@hapi/hapi/lib/types/server/server.d.ts:4:22 - error TS2307: Cannot find module 'joi' or its corresponding type declarations.

4 import { Root } from 'joi';
                       ~~~~~


Found 2 errors in 2 files.

Errors  Files
     1  node_modules/@hapi/hapi/lib/types/route.d.ts:2
     1  node_modules/@hapi/hapi/lib/types/server/server.d.ts:4

note : npm i joi resolves the error.

a possible fix

import { ObjectSchema, ValidationOptions, SchemaMap, Schema } from 'joi';

could it be?

 import { ObjectSchema, ValidationOptions, SchemaMap, Schema } from '@hapi/validate'; 
@kanongil
Copy link
Contributor

Yeah, hapi should not import typings directly from joi.

I don't know if your suggestion will work, and suspect that it can cause other issues when used.

The real solution is probably to expose those objects through a new generic, that can ideally be inferred.

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

No branches or pull requests

2 participants