我试图向这样的对象数组声明一个空数组:
const App: React.FC = () => {
const [todos, setTodos] = useState([] as TodoArray[]);
interface TodoArray {
[index: number]: Todo;
}
interface Todo {
userId: number;
id: string;
title: string;
completed: boolean;
}
useEffect(() => {
axios('xxx').then(res => {
let todos = res.data;
setTodos(todos);
});
}, []);
return (
<div className='App'>
<p>
{todos.map(todo => (
<p>{todo.title}</p>
))}
</p>
</div>
);
};
我希望打字稿可以识别数组中每个对象的所有属性,但是不起作用。它警告“ TodoArray”上不存在属性“ title”。 正确的用法是什么?谢谢。
答案 0 :(得分:0)
var $allVideos = $('video').on('ended', function() {
$('.playpause').css("opacity", 1);
});
var $allPlayPause = $('.playpause');
$allPlayPause.on('click', function() {
var $playpause = $(this),
video = $playpause.parent().find("video")[0];
if (video.paused) {
video.play();
$allPlayPause.css('opacity', 1');
$playpause.css("opacity", 0)
// pause all but this:
$allVideos.not(video).each(function(i, vid) {
vid.pause();
});
} else {
video.pause();
$playpause.css("opacity", 1)
$('.playpause').show();
}
});
尝试这个让我知道是否有任何错误