DEV Community

Discussion on: 7 Tips for Clean React TypeScript Code you Must Know 🧹✨

Collapse
 
lifeiscontent profile image
Aaron Reisman

fwiw, you shouldn't be using interfaces unless you want to enhance a type.

e.g.:

interface Example {}

interface Example {
    foo: 'bar';
}

interface Example {
    baz: 'qux';
}

type Foo = Example['foo'];
type Baz = Example['baz'];


// @ts-expect-error TExample is defined
type TExample = {}

// @ts-expect-error TExample cannot be redefined
type TExample = {
    foo: 'bar';
}
Enter fullscreen mode Exit fullscreen mode