I can define types for destructured function arguments in TypeScript:
import { state, myAction } from "store/types";
type Args = {
state: state;
action: myAction;
};
const move = ({ state, action }: Args) => {
However can you specify the types inline? So something like:
const move = ({ state: state, actionL: actionMoveExerciseUp }) => {
Then you will need to do this:
const move = ({ state, action }: { state: state, action: myAction }) => {
// More logic here
}
This is because your original code is actually simply reassigning the value to another variable . ({ state: state, action: actionMoveExerciseUp })
means that the value of action
will be accessible as actionmoveExercuseUp
inside the scope of the arrow function instead of action
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.