TypeScript – How can pick off some properties from a interface in TypeScript?

You can use the buit-in Pick type to get part of an interface :

type PostsInfoWithoutConent= Pick<PostsInfo, "id" | "title">

If you just want to exclude one property you might be better off defining the the Omit type and use that

type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T];  
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>; 
type PostsInfoWithoutContent= Omit<PostsInfo, "md_content">

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)