Pick<T, K>

Last updated: 2026-10-22

Pick<T, K> Pick

Pick<T, K> plucks the properties named by K out of T into a new type. When you only need a slice of a big type (list summaries, subset parameters), there is no need to hand-write a duplicate — and if the source field types change, the Picked type follows automatically.

GroupUtility Types
KindType
Strict modeNot required

ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.

📝 Syntax

type Pick<T, K extends keyof T> = {
  [P in K]: T[P];
};

// Usage
type OrderSummary = Pick<Order, "id" | "buyer" | "total">;

⚙️ Parameters

TThe source object type whose properties are selected
K extends keyof TThe union of keys to keep; must be existing keys of T — a misspelled key is a compile error (Pick's safety net)

Returns:A new type containing only the properties named by K, with the same types as in T.

▶ Example

Edit the code below and click Try it to see the transpiled result:

Output:

{"id":"A-1024","buyer":"Carol","total":259}

(Runtime output after transpilation; accessing order.address on an OrderSummary is a compile error — fields outside the Pick whitelist do not exist in the type)

💡 Notes

ℹ️ Info Implementation: type Pick<T, K extends keyof T> = { [P in K]: T[P] } — K is a key union and the mapped type pulls each property type in turn.
⚠️ Note Pick is a whitelist: fields added to Order later will not appear in the Picked type. If your intent is "everything except a few", use Omit (blacklist) instead — otherwise new fields silently drop out.
💡 Tip Rule of thumb: few fields wanted → Pick; few fields to drop → Omit. Both are shallow type-level selections — nested objects remain shared references.
More cases coming soon.

📚 Related tutorials

❓ FAQ

Q Does mutating a Picked object affect the original?
A Pick selects properties at the type level only; it copies no data. Runtime sharing depends on your code (the example's toSummary builds a fresh object via destructuring); if you pass the same object reference, mutations are of course visible to both.
Q What happens if I pick a key that does not exist?
A Compile error: Type '"oderId"' is not assignable to type 'keyof Order'. K is constrained to keyof T, so typos surface immediately — which makes Pick safer than Omit (which performs no such check).
Q Can Pick include methods too?
A Yes. Methods are properties, so Pick<T, "save"> yields a type like { save: () => void } with the same this-binding expectations as the original.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏