jquense / yup

Dead simple Object schema validation
MIT License
22.93k stars 934 forks source link

Readme document object InferType doesn't work as documented. #2170

Closed cmtheit closed 9 months ago

cmtheit commented 10 months ago

To Reproduce Those code just shown in readme.md:

const userSchema = object({
  name: string().required(),
  age: number().required().positive().integer(),
  email: string().email(),
  website: string().url().nullable(),
  createdOn: date().default(() => new Date()),
});

type User = InferType<typeof userSchema>;
/* {
  name: string;
  age: number;
  email?: string | undefined
  website?: string | null | undefined
  createdOn: Date
}*/

But in vscode extension ms-vscode.vscode-typescript-next I just got this type for User (when I hover my mouse on it):

type User = {
    name?: string;
    age?: number;
    email?: string;
    website?: string;
    createdOn?: Date;
}

I have tried typescript@4.7 for older version of NonNullable and then noticed that typescript: "^4.9" was using in current yup's devDependencies. And I switch to that version, using vscode command Select Typescript Version to select the workspace typescript sdk. Successfully switching to the specific version, but it still doesn't work.

Expected behavior Just as documented, get an non optional object key inference.

Platform (please complete the following information):

Additional context I have searched but amazingly found that few issue about this issue described.

jquense commented 9 months ago
image

This is working for me with TS 5.4, perhaps you don't have strictNullChecks set to true in your ts config