export type ConditionDocPrko = { covenantsDocId: string number; documentType:…
- User
export type ConditionDocPrko = { covenantsDocId: string | number; documentType: 'COVENANTS_STANDARD'; onClose: NoopFn; readOnly?: boolean; };
export interface ConditionDocDCStandard extends ConditionDocPrko { documentType: 'DELAYED_CONDITIONS_STANDARD'; } Interface 'ConditionDocDCStandard' incorrectly extends interface 'ConditionDocPrko'. Types of property 'documentType' are incompatible. Type '"DELAYED_CONDITIONS_STANDARD"' is not assignable to type '"COVENANTS_STANDARD" how correct this
- Assistant
The error you're encountering is due to the fact that TypeScript sees the
documentTypein theConditionDocDCStandardinterface as a string literal type that is different from the in the interface. - User
switch (props.documentType) { case 'COVENANTS_PROTOTYPE': { return { ...defaultProps, isConditionKfulDoc: true }; } case 'DELAYED_CONDITIONS_STANDARD': { return { ...defaultProps, simplifiedFormulation: true }; } case 'COVENANTS_STANDARD': { return { ...defaultProps }; } } how add type to switch case in function
- Assistant
To add type safety to the
switchstatement based on theprops.documentType, you can follow these steps: - User
export const createConditionProps = (props: ConditionDocProps) => { const defaultProps = { ...props, isConditionKfulDoc: false, simplifiedFormulation: false, };
codeswitch (props.documentType) { case 'COVENANTS_PROTOTYPE': { return { ...defaultProps, isConditionKfulDoc: true }; } case 'DELAYED_CONDITIONS_STANDARD': { return { ...defaultProps, simplifiedFormulation: true }; } case 'COVENANTS_STANDARD': { return { ...defaultProps }; } }}; how add return type to the function if ConditionDocProps is export type ConditionDocProps = ( | ConditionDocPrko | ConditionDCStandardDocPrko | ConditionDocKful ) & { isOpen: boolean };
- Assistant