TypeScript Best Practices —Useless Interfaces, Classes, and Promises

John Au-Yeung
The Startup
Published in
3 min readJun 2, 2020

--

Photo by emy on Unsplash

TypeScript is an easy to learn extension of JavaScript. It’s easy to write programs that run and does something. However, it’s hard to account for all the uses cases and write robust TypeScript code.

In this article, we’ll look at the best practices to following when writing code with TypeScript, including not writing empty interfaces.

Also, we should use promises in a useful way.

The any type also shouldn’t be used.

Also, classes shouldn’t be used as namespaces in TypeScript.

No Empty Interface Declarations

Empty interfaces aren’t very useful. Therefore, we probably don’t want them in our code.

So instead of writing:

interface Foo {}

or:

interface Baz extends Foo {}

We write:

interface Foo {
name: string;
}

or:

interface Baz extends Foo, Bar {}

Extending 2 types inherit members from both types, so that may be useful.

Don’t use the any Type

--

--