ts-book
ts-book copied to clipboard
[p.52, 오타] fetch any 타입 정의 오타
fetch("url").then((response) => {
return response.json();
}).them((result) => { // (parameter) result: any
});
const result = JSON.parse('{"hello":"json"'); // const result: any
fetch("url").then<{ data: string }>((response) => {
return response.json();
}).them((result) => { // (parameter) result: { data: string; }
});
const result: { hello: string } = JSON.parse('{"hello":"json"');
두 구문 모두 밑의
const result: { hello: string } = JSON.parse('{"hello":"json"}');
중괄호가 누락된 것 같습니다.