Coding Global Background
Coding Global

TypeScript Devs: How do you name your private class fields?

Archived 2 months ago
4 messages
3 members
Created 3 months ago
Updated 3 months ago
Open in Discord
H
은혜
Script Kiddie!
I'm just curious what y'all prefer for a private field naming in Typescipt.
These would be backing fields for public getters, so they need a different name from the getters themself.

Option 1 — Native JS private fields (harder to debug, not supported everywhere, I personally hate them on large projects):
#aspectRatio: number;
#width: number;
#zoom: number = 1.0;

Option 2 — Underscore prefix (brought to you by the ugliest language in the world Java):
private _aspectRatio: number;
private _width: number;
private _zoom: number = 1.0;

Option 3 — Add “Value” suffix (the lazy option):
private aspectRatioValue: number;
private widthValue: number;
private zoomValue: number = 1.0;

Option 4 — More descriptive names (requires unconventional naming that might confuse some devs):
private currentAspect: number;
private storedWidth: number;
private zoomLevel: number = 1.0;


What do you prefer using or seeing in a real codebase, and why?

Replies (2)