I have an interface that describe the data structure from BE, and a class has method for transforming that BE data structure to our FE data structure and vice versa,but during that typescript throw Type 'string | number' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'
error. How do i resolve it, and why it happen ?
interface BEStructure {
a?: string;
b?: number;
...
}
class FEStructure {
a: string = null;
b: number = null;
...
static convertToBE(fe: Partial<FEStructure>): BEStructure {
const be: BEStructure = {};
Object.keys(fe).forEach(key => {
switch (key) {
case 'a':
case 'b':
// My others logic
// ERROR HERE
be[key] = fe[key];
break;
default:
be[key] = fe[key];
}
});
return be;
}
}
I created a reproduce here