grantila / grantila/suretype

Object validator not type checking as expected

Open
#40 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
505
Forks
8
PR merge metrics
No merged PRs in 30d

Description

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 = 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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.