Utility Types
Partial<Type>
Partial<Type>interface Post {
title: string
body: string
imageUrl: string
}
type PostFields = Partial<Post>
// เหมีอนกันกับ
interface PostFields {
title?: string
body?: string
imageUrl?: string
}
function updatePost(post: Post, fields: PostFields) {
...
}
const post = { title: "...", body: "...", imageUrl: "..." }
// Update เฉพาะ Body ของ Post
const updatedPost = updatePost(post, { body: "..." }) Pick<Type,Keys>
Pick<Type,Keys>Omit<Type,Keys>
Omit<Type,Keys>Record<Keys,Type>
Record<Keys,Type>Parameters<FunctionType>
Parameters<FunctionType>ReturnType<FunctionType>
ReturnType<FunctionType>Last updated