I’m new to typescript and am writing some classes to work as a very simple ORM for my project. I just learned how to require that a parameter conform to an interface, like so:
interface UserInfo {
userId: string
email?: string
// many more properties...
}
class User {
constructor(connection: typeof db, init: UserInfo) {
// code here
And I understand that the syntax to set default values for those optional properties is:
class User {
constructor(connection: typeof db, {email = null, /*...*/}: UserInfo) {
// code here
But my UserInfo
interface is long, what if I want to only specify/default a few of the properties, without typing out a giant object in the parameters for the constructor of this object? Is there a way to require an entire interface, but destructure only some properties?