Skip to content

Types of object are incorrect #2978

@felixmosh

Description

@felixmosh
Contributor

Support plan

  • is this issue currently blocking your project? (yes):
  • is this issue affecting a production system? (no):

Context

  • node version: 18
  • module version with issue: 17.9.2
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

const portSchema = Joi.number().integer().greater(2999).positive().required();
const hostSchema = Joi.alternatives([Joi.string().ip(), Joi.string().domain().allow('localhost')]).required();

const envSchema = Joi.object({
  NODE_ENV: Joi.string().valid('production', 'development', 'test').required(),
  PORT: portSchema.default(3000).optional(),
  SERVICE_HOST: hostSchema,
  REDIS_PORT: portSchema,
  REDIS_HOST: hostSchema,
});

What was the result you got?

envSchema gets a type of Joi.ObjectSchema<any> instead of specific object,
image

What result did you expect?

It should contain reflect the object type...

Maybe we can use the types from https://github.com/maghis/types-joi/blob/master/index.d.ts which do work

I've managed to change types to reflect object's keys by modifying this

object<TSchema = any, isStrict = false, T = TSchema>(schema?: SchemaMap<T, isStrict>): ObjectSchema<TSchema>;

into

object<TSchema = any, isStrict = false>(schema?: SchemaMap<TSchema, isStrict>): ObjectSchema<TSchema>;

image

But it sets unknown to each key.

Activity

added
supportQuestions, discussions, and general support
on Aug 23, 2023
linked a pull request that will close this issue on Aug 24, 2023
changed the title [-]Types of object are incorrect[/-] [+]Types of `object` are incorrect[/+] on Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportQuestions, discussions, and general support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @felixmosh

      Issue actions

        Types of `object` are incorrect · Issue #2978 · hapijs/joi