Quiz 1.
interface Video {}
interface Book {}
interface Content {}
function watchVideo(content: Content<Video>) {
console.log(`${content.info.playTime}μκ°μ κ°μλ₯Ό μμ²ν¨`);
}
function readBook(content: Content<Book>) {
console.log(`${content.info.pageNumber}κΆμ μ±
μ μ½μ`);
}
watchVideo({
name: "ν μ
ν¬κΈ°λ‘ μλΌλ¨Ήλ νμ
μ€ν¬λ¦½νΈ",
info: {
playTime: 10.5,
},
});
readBook({
name: "ν μ
ν¬κΈ°λ‘ μλΌλ¨Ήλ 리μ‘νΈ",
info: {
pageNumber: 700,
},
});
βοΈλ΅μ
interface Video {
playTime: number;
}
interface Book {
pageNumber: number;
}
interface Content<T> {
name: string;
info: T;
}
μ½λλ§ν¬
Quiz 2.
interface Comment {
id: number;
author: string;
content: string;
}
function getComments() {
return new Promise((resolve) => {
setTimeout(() => {
resolve([
{
id: 1,
author: "μ΄μ ν & κΉν¨λΉ",
content: "νμ
FE μ±λ¦°μ§! μκ°κΉμ§ νμ΄ν
!",
},
]);
}, 2000);
});
}
import { Equal, Expect, NotEqual } from "@type-challenges/utils";
type TestCases = [
Expect<NotEqual<ReturnType<typeof getComments>, Promise<any>>>,
Expect<NotEqual<ReturnType<typeof getComments>, Promise<unknown>>>,
Expect<NotEqual<ReturnType<typeof getComments>, Promise<never>>>,
Expect<Equal<ReturnType<typeof getComments>, Promise<Comment[]>>>
];
βοΈλ΅μ
function getComments():Promise<Comment[]> {
return new Promise((resolve) => {
setTimeout(() => {
resolve([
{
id: 1,
author: "μ΄μ ν & κΉν¨λΉ",
content: "νμ
FE μ±λ¦°μ§! μκ°κΉμ§ νμ΄ν
!",
},
]);
}, 2000);
});
}
μ½λλ§ν¬