TypeScript: `type` vs `interface`, lequel choisir ?

asked a month ago335 viewsfr

4

Dans quels cas utiliser type et dans quels cas interface ? Y a-t-il des différences de performance ou de messages d'erreur ?

🤖 AI diagnosis

AI-generated. Not an answer — the community below confirms or corrects it. Always verify before relying on it.

asked a month ago

3 Answers

3
Accepted answer

Prisma is the most productive choice: typed client, prisma migrate for versioned SQL, and migrate deploy in CI/production. Keep migrations in git, never edit applied ones, and run migrate deploy as a release step.

Sign in to tell others whether this worked.

answered a month ago
2

Wrap handlers so rejections reach your error middleware:

const wrap = fn => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
app.get('/x', wrap(async (req, res) => { /* ... */ }));

Or upgrade to Express 5, which does this automatically.

Sign in to tell others whether this worked.

answered a month ago
1

Use interface for object shapes you might extend or that represent a public API; use type for unions, intersections, mapped and conditional types. Performance is identical for simple cases; interface error messages are sometimes cleaner.

Sign in to tell others whether this worked.

answered a month ago

Sign in and verify your email to post an answer.