Builder pattern for typescript types.
npm install @thecodeaware/ts-interface-builder







> Builder pattern for typescript types.
``bash
npm install @thecodeaware/ts-interface-builder
`
`typescript
import { builderOf } from '@thecodeaware/ts-interface-builder';
interface Input {
label: string;
value: number;
title?: string;
}
const input: Input = builderOf().title('title').label('label').value(2).build();
// with default object
const inputWithDefaults: Input = builderOf({
title: 'defaultTitle',
label: 'defaultLabel',
value: 1,
})
.title('title')
.value(2)
.build();
`
Feel free to add improvements. Remember about the tests!
`bash`
npm install
`bash`
npm run test
1. Why not API with with prefix like withLabel for label property?
It is possible with TS but it brings more edge cases.
`tswith${Capitalize
export type TypeBuilder
[P in keyof T as ]: (arg: T[P]) => TypeBuilder`
} & {
build(): T;
};
- Object with capitalized property.
- Object with capitalized and non-capitalized property like label and Label`.