I’ve been facing this problem for a long time in my repo and I can’t figure out what it’s due to:
`
Failed to compile.
src/store/documents/documents.slice.ts
TypeScript error in src/store/documents/documents.slice.ts(30,35):
Type '{ areDocumentsLoading: true; shouldFetchDocuments: false; list: WritableDraft<ContractDocument>[]; isDocDownloadLoading: boolean; hasDocumentsLoadingError: boolean; }' is not assignable to type 'IDocumentsState'.
Types of property 'list' are incompatible.
Type 'WritableDraft<ContractDocument>[]' is not assignable to type 'ContractDocument[]'.
Type 'WritableDraft<ContractDocument>' is not assignable to type 'ContractDocument'.
Types of property 'user' are incompatible.
Type 'WritableDraft<User> | null' is not assignable to type 'User | null'. TS2322
28 | builder.addCase(
29 | fetchDocuments.pending,
> 30 | (state): IDocumentsState => ({
| ^
31 | ...state,
32 | areDocumentsLoading: true,
33 | shouldFetchDocuments: false
The error does not appear at build time or when the app is first launched. It ONLY appears when I make a modification, so I have to Ctrl+C and relaunch the app to see my changes without this error.
Here is my typescript version : 4.9.5 , reduxjs/toolkit : 1.9.0.
My code looks perfectly good on this side, I think a version of redux/typescript block me.
Here is ContractDocument class :
export default class ContractDocument extends CommonEntity {
user: User | null;
instance: ContractInstance | null;
tasks: Task[];
filename: string;
s3_path: string;
status: number;
archived: number;
private: number;
displayed: boolean;
hideDownloadPage: boolean;
needsLawyerApproval: boolean;
documentIndex: number;
contractData: ContractData | null;
expiresAt?: Date;
}
Here is IDocumentState :
const initialState: IDocumentsState = {
list: [],
areDocumentsLoading: false,
isDocDownloadLoading: false,
hasDocumentsLoadingError: false,
shouldFetchDocuments: false
}
And finally, the error append here :
builder.addCase(
fetchDocuments.pending,
(state): IDocumentsState => ({
...state,
areDocumentsLoading: true,
shouldFetchDocuments: false
})
)
Thank you for any information you may have on this subject.
I’ve tried changing the version of typescript, as well as reduxjs/toolkit.
Jo Cluzet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.