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

poze a month ago334 gadefr

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 ?

🤖 Dyagnostik IA

Se IA ki fè l. Se pa yon repons — kominote a anba a konfime oswa korije l. Toujou verifye anvan ou fye l.

poze a month ago

3 Repons

3
Repons yo aksepte

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.

Konekte pou di lòt moun si li te mache.

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.

Konekte pou di lòt moun si li te mache.

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.

Konekte pou di lòt moun si li te mache.

answered a month ago

Sign in and verify your email to post an answer.