'How to avoid self referring an object in Typescript?
I have this kind of code:
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const useStore = create<StoreState>((set, get) => {
const jwtClient = createJWTClient(useStore);
return {
dummyState: createDummySlice(set, get, jwtClient),
userState: createUserSlice(set, get, jwtClient),
};
});
The function createJWTClient needs the useStore in order to access user tokens and make auth calls.
Also the slices need the jwtClient in order to call some methods with this instance.
The problem is that I refer the useStore object before is actually created but I thought this is just a pointer thing but Typescript complains that:
TS7022: 'useStore' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
TS7022: 'jwtClient' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
