-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Autocomplete bug on vscode when using action in prepare/reducer format #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you validate if it works when you annotate the method parameters? const todosSlice = createSlice({
...
reducers: {
addTodo: {
/** @param {import('@reduxjs/toolkit').PayloadAction<{text: string, id: number}>} action */
reducer(state, action) {
const { id, text } = action.payload;
state.push({ id, text, completed: false });
},
/** @param {string} text */
prepare(text) {
return { payload: { text, id: nextTodoId++ } };
},
},
...
},
}); |
Tested on project and works fine ! |
Yeah. So our TypeScript support is so good that it even works for JavaScript (which is why you are getting all that autocomplete), but there are some edge cases where our TypeScript cannot catch on everything that JavaScript code without types does. |
Yeah it's pretty awesome !
Thank you if a fix is possible, it would be perfect :). |
When I used prepare in Typescript, a type error occurred. Is it related to this issue? toggleTodo: {
reducer(state, action) {
const todo = state.find((todo) => todo.id === action.payload)
if (todo) {
todo.completed = !todo.completed
}
},
// type error here
prepare(id) {
return {
payload: id,
// error: undefined,
// meta: undefined,
}
}
} |
@sweetliquid the prepare notation requires you to specify an explicit type for the |
Yes thank you, it works. |
I get an issue with vscode autocomplete when using slice with actions in reducer/prepare format.
I have build a small project to demonstrate.
Inside the src/features/todos you have the slice that include a "basic" function addTodo and a version with the format reducer/prepare. If you use the reducer/prepare version you shoudn't be able to access to autocomplete in other file from the folder (src/features/todos) but it just work well if you use the other version.
You still could see autocomplete with 'abc' symbols if you already use the function but that's all.
The text was updated successfully, but these errors were encountered: