I’d like to use JSDoc
type hints as much as possible.
But in some cases, defining hints is tricky.
In this case, it is Svelte
‘s Store
.
After much effort, I succeeded with the following code:
import { writable } from 'svelte/store';
/** @type{import('svelte/store').Writable<{nick:string, img:string}|null>} */
export const userInfoStore = writable(null);
The above code works perfectly in my VS Code
environment.
But it is a bit annoying.
So I also found the following way, with a very, very small overhead:
export const userInfoStore2 = writable((
(
/** @type{{nick:string, img:string}|null} */
val
) => val
)(null));
This works perfectly, but I don’t like the fact that the actual code is affected, not the comments, just for my convenience.
This is my best.
I tried several codes like the following, but they all failed:
export const userInfoStore3 = writable(
/** @type{{nick:string, img:string}|null} */
null
);
/** @type{{nick:string, img:string}|null} */
let userInfoDef4 = null;
export const userInfoStore4 = writable(userInfoDef4);
let userInfoDef5 = null;
export const userInfoStore5 = writable(
/** @type{{nick:string, img:string}|null} */
userInfoDef5
);
Any other ideas?