Я использую react-redux
hook useSelector
с TypeScript.Есть ли поддержка статической типизации?Теперь мне нужно разыграть, используя ключевое слово as
.
interface User { age: number }
const selectUser = (state): User => state.user.detail
const MyComponent = () => {
const user1 = useSelector(selectUser)
user1.age = 'This is not number.' // No warning or error.
const user2 = useSelector<User>(selectUser)
user2.age = 'This is not number.' // No warning or error.
const user3 = useSelector(selectUser) as User
user3.age = 'This is not number.' // TS2339 error, but with casting.
}