S
SolidJS14mo ago
Mr Void

setState - typescript : Argument of type 'string' is not assignable to parameter of type 'never'

Receiving the following error:
Argument of type 'string' is not assignable to parameter of type 'never'
Argument of type 'string' is not assignable to parameter of type 'never'
for the line:
setState("user", "id", () => data.id);
setState("user", "id", () => data.id);
Context:
function createUserStoreDispatch(setState: SetStoreFunction<StoreState>): UserStoreDispatch {
return {
login(data: loginData) {
batch(() => {
setState("user", "id", () => data.id);
// ... ^ TYPESCRIPT ERROR
});
}
}
}
function createUserStoreDispatch(setState: SetStoreFunction<StoreState>): UserStoreDispatch {
return {
login(data: loginData) {
batch(() => {
setState("user", "id", () => data.id);
// ... ^ TYPESCRIPT ERROR
});
}
}
}
export type StoreState = {
user: UserStore
} | object

export default function StoreProvider(props: any) {
const [state, setState]: [Store<StoreState>, SetStoreFunction<StoreState>] = createStore<StoreState>({});
export type StoreState = {
user: UserStore
} | object

export default function StoreProvider(props: any) {
const [state, setState]: [Store<StoreState>, SetStoreFunction<StoreState>] = createStore<StoreState>({});
Why is the type "never" ?
1 Reply
Otonashi
Otonashi14mo ago
because user can't index { user: UserStore } | object since it contains object
Want results from more Discord servers?
Add your server