Skip to content

Can't override field with .keys() #3

@d9k

Description

@d9k

Getting is not assignable to type 'never' error on overriden field use:

export const CreatureV1Schema = joi.object({
  name: joi.string().required(),

  // accepts textual representation of the size ('big', 'normal', 'small' etc)
  size: joi.string().required(),
});

export const CreatureV2Schema = CreatureV1Schema.keys({
  // accepts size in meters now
  size: joi.number().required(),
});

export type CreatureV2 = joi.extractType<typeof CreatureV2Schema>;

export const creatureV2: CreatureV2 = {
  name: 'ogre',

   // TS2322 error: Type 'number' is not assignable to type 'never'.
  size: 3.5,
};

CreatureV2 renders to

type CreatureV2 = {} & {
    name: string;
    size: string;
} & {} & {
    size: number;
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions