bem-react
bem-react copied to clipboard
feat(di): check types in registry
resolve #386
Example:
interface MyReg {
A: React.ComponentType<{ a: string }>,
C: React.ComponentType<{ c: string }>
}
const id = 'RegistryId'
const A: React.FC<{ a: string }> = () => null
const B: React.FC<{ b: string }> = () => null
const C: React.FC<{ c: string }> = () => null
const AB: React.FC<{ a: string, b: string }> = () => null
Case 0: Pre check (missing props)
const registry = new Registry<MyReg>({ id }, {
A,
// TS Error: Property 'C' is missing
});
const expRegistry = new Registry<Partial<MyReg>>({ id }, {
A
}); // Ok
Case 1: Pre check
const registry = new Registry<MyReg>({ id }, {
A,
B, // TS Error: 'B' does not exist in type 'MyReg'
C
});
Case 2: Post check
const registry = new Registry<MyReg>({ id });
registry.set('A', A); // Ok
registry.set('A', B); // TS Error
registry.set('A', AB); // Ok
Case 3: Hints
