From 4934ba79b15e2dacdf4f7165fe848e5fccc3eca2 Mon Sep 17 00:00:00 2001 From: Georgii Dolzhykov Date: Tue, 29 Aug 2017 23:04:43 +0300 Subject: [PATCH] README.md: add one more common mistake (#19436) * README.md: add one more common mistake * add article * expanded the explanation a bit, added examples, * wording * s/better/more specific/ --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 29d174ef77..e4c027648f 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ For a good example package, see [base64-js](https://github.com/DefinitelyTyped/D Example where a type parameter is acceptable: `function id(value: T): T;`. Example where it is not acceptable: `function parseJson(json: string): T;`. Exception: `new Map()` is OK. +* Using the types `Function` and `Object` is almost never a good idea. In 99% of cases it's possible to specify a more specific type. Examples are `(x: number) => number` for [functions](http://www.typescriptlang.org/docs/handbook/functions.html#function-types) and `{ x: number, y: number }` for objects. If there is no certainty at all about the type, [`any`](http://www.typescriptlang.org/docs/handbook/basic-types.html#any) is the right choice, not `Object`. If the only known fact about the type is that it's some object, use the type [`object`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#object-type), not `Object` or `{ [key: string]: any }`. #### Removing a package