getters-setters
v1.0.1
Published
This package exports two types: `GettersSetters` and `FlattenGettersSetters` that lets you create getter and setter types for a given object type.
Downloads
8
Maintainers
Readme
This package exports two types: GettersSetters
and FlattenGettersSetters
that lets you create getter and setter types for a given object type.
import { GettersSetters, FlattenGettersSetters } from 'getters-setters';
interface User {
name: string,
age: number
}
type UserGettersSetters = GettersSetters<User>
type FlattenUserGettersSetters = FlattenGettersSetters<User>
Here are what looks like types generated for the User interface.
type UserGettersSetters = {
name: {
getName: () => string;
setName: (v: string) => void;
};
age: {
getAge: () => number;
setAge: (v: number) => void;
};
}
type FlattenUserGettersSetters = {
getName: () => string;
setName: (v: string) => void;
} & {
getAge: () => number;
setAge: (v: number) => void;
}