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

Object validator not type checking as expected #40

Open
saramcicchi opened this issue Sep 27, 2023 · 0 comments
Open

Object validator not type checking as expected #40

saramcicchi opened this issue Sep 27, 2023 · 0 comments

Comments

@saramcicchi
Copy link

Say we have the following TS interface

interface Fish {
   name: string;
}

If you create an object of that type and give it extra properties, Typescript throws an error.

let fish: Fish = {
   name: 'Bubbles',
   numberOfLegs: 2
};

Type '{ name: string; numberOfLegs: number; }' is not assignable to type 'Fish'.
Object literal may only specify known properties, and 'numberOfLegs' does not exist in type 'Fish'.

However, if you create an object validator with extra properties, no type error occurs.

let fishValidator: ObjectValidator<Fish> = v.object({
   name: v.string().required(),
   numberOfLegs: v.number().required()
});

I would expect the same error to be reported if extra properties exist in the object validator definition but do not exist in the specified type. Am I misunderstanding something here? Thanks in advance!

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

1 participant