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

A simple PR that adds enforcing onto schema #9958

Merged
merged 7 commits into from
Feb 22, 2021

Conversation

ShadiestGoat
Copy link
Contributor

Summary
With this, when creating a new schema using typescript, you get enforcing for built in types. Solves issue #9946. I know I mentioned I wouldn't create a PR but I kinda got impatient aha.
It's really annoying to not have auto complete on IDEs when writing strings, but with this bad boy of a PR, it prioritizes the built in types, so this way SchemaDefinition<T> doesn't affect anything

Examples

interface IUser {
   username: string,
   password: string,
   age: number
}
//old
new Schema<IUser & Document, Model<IUser & Document>, IUser>({
      username: "adjasd",
      password: "sad",
      age: "jkd"
})
// no errors, no auto complete :O

//new
new Schema<IUser & Document, Model<IUser & Document>, IUser>({
      username: "adjasd",
      password: "sad",
      age: "jkd"
})
//big time errors because adjasd and sad isn't "String" | "string", and jkd isnt "Number" | "number", autocomplete!

@ShadiestGoat
Copy link
Contributor Author

Uhh the checks aren't relevant to the PR.

ShadiestGoat and others added 4 commits February 21, 2021 01:55
I forgot to add this before I guess. This way, if T is a string/number/function, then it shows it as well. If it is another type, it also shows it (which is why it isn't any).
Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is very clever. Thanks 👍

@vkarpov15 vkarpov15 added this to the 5.11.18 milestone Feb 22, 2021
@vkarpov15 vkarpov15 added the typescript Types or Types-test related issue / Pull Request label Feb 22, 2021
@vkarpov15 vkarpov15 merged commit 9d396d2 into Automattic:master Feb 22, 2021
vkarpov15 added a commit that referenced this pull request Feb 23, 2021
This was referenced Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants