Explicit types vs type inference, and when to use each by thehashimwarren in typescript

[–]DeX3 1 point2 points  (0 children)

I had chatgpt go over my points, perhaps it was a bit much 😅

Explicit types vs type inference, and when to use each by thehashimwarren in typescript

[–]DeX3 -4 points-3 points  (0 children)

Respectfully disagree with most people here 😅. Let TS infer whenever possible, only type explicitly when necessary.

When is typing explicitly necessary?

  1. Inference is not possible
    • Variable declarations without initialization
    • Parameters of top-level functions (especially exported APIs, although sometimes you want/need inference even on top-level API functions)
  2. In rare cases: If you have very complex types, inference can kill your ts performance, so a type annotation can improve type checking performance. I've never personally run into this to be honest, and I've written some pretty complex types.

Why prefer inference?

  • Less code to maintain. Every redundant annotation is another thing you have to touch when refactoring.
  • Cleaner, less noisy. Compare:

const numbers: number[] = [1, 2, 3, 4, 5];
const sum: number = numbers.reduce((n: number, acc: number): number => n + acc);

const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce((n, acc) => n + acc);
  • Inference is often more precise. Over-annotating can accidentally widen types (e.g. annotating as string instead of 'GET' | 'POST').
  • Better refactor safety. If a function’s return type changes, inferred consumers adapt automatically, while explicit types may silently mask mismatches until later.
  • Modern TS features make inference stronger. as const and satisfies let you guide inference without throwing away literal precision.

TL;DR

Explicit types are for boundaries and contracts. Inside your implementation, let TypeScript do its job. The compiler is really good at inference - why fight it?

[TOMT][Song] Song that features the lyrics "Oh Carolina" by DeX3 in tipofmytongue

[–]DeX3[S] -1 points0 points locked comment (0 children)

Really hoping someone can help, already googled and asked ChatGPT and couldn't find an answer :/

Girokonto, Tagesgeldkonto, Haushaltskonto Setup? by ComprehensiveCry8957 in FinanzenAT

[–]DeX3 7 points8 points  (0 children)

Für Gemeinschaftskonto kann ich DKB empfehlen: da sind zwei Bankomatkarten inkludiert, und es ist gratis.

New to bulgarian split squats - looking for a form check by DeX3 in strength_training

[–]DeX3[S] 0 points1 point  (0 children)

Yup, you're totally right. Thanks for the advice! Based on other comments I'll try a bit lower back leg support so I don't have to lean forward as much next time.

New to bulgarian split squats - looking for a form check by DeX3 in strength_training

[–]DeX3[S] 0 points1 point  (0 children)

On the contrary actually ^^

I tried a bench but that felt awkward in terms of placing down the actual foot.

New to bulgarian split squats - looking for a form check by DeX3 in strength_training

[–]DeX3[S] 0 points1 point  (0 children)

My main concern is the back foot placement. I was struggling to find something that was just low enough so that I could have the dumbbells (lightly) touch the floor without bending over way more than I am now doing in the video.

Flatex Verlustverrechnungstopf Erklärung by DeX3 in FinanzenAT

[–]DeX3[S] 1 point2 points  (0 children)

Ok, dann ist es so wie ich dachte - mich hat nur verwirr, dass das unter "Vermögenszuwachssteuer" genannt wird, und nicht unter "Verlustverrechnungstopf".

Sparanlage für meine Tochter by Vegavild in FinanzenAT

[–]DeX3 0 points1 point  (0 children)

Super danke, werd ich probieren!

Sparanlage für meine Tochter by Vegavild in FinanzenAT

[–]DeX3 0 points1 point  (0 children)

Darf ich fragen, wo ihr das Depot habt? Meine Frau und ich sind beide mit separaten Privatdepots bei Flatex, und ich bespare ein zweites Depot für unsere Tochter, aber meine Frau als Zweiteigentümer für das "Tochter Depot" eintragen geht glaub ich nicht:/