Content pfp
Content
@
0 reply
0 recast
0 reaction

typeof.eth 🔵 pfp
typeof.eth 🔵
@typeof.eth
TIL that in TypeScript, if you define a class with readonly properties and an empty constructor, TypeScript will automatically assign the properties to the class. Not sure if I love that, tbh, since I was under the impression that TS tends to not modify logic...
4 replies
6 recasts
35 reactions

Phil Cockfield pfp
Phil Cockfield
@pjc
maybe they are encouraging people to not use `class` by sprinkling scary magic there! 😅🥹
0 reply
0 recast
3 reactions

Darryl Yeo 🛠️ pfp
Darryl Yeo 🛠️
@darrylyeo
Same deal for `public name` / `private name` / `protected name`. Pretty sure they did it this way so you don’t have to repeat the same definitions in the class body. Downside of this shorthand is you’re limited to using single ordered arguments in the constructor. https://www.typescriptlang.org/play/?#code/MYGwhgzhAEAqAWBLAdgc2gbwFAEhgHtkIAXAJwFdhj9SAKXHAB1P2IFMq2ATaMALmglSKVABoGjcgCMQiYNCkChI8TibCAbmHbRgSsitwBKTFlwBfLOaA
1 reply
0 recast
2 reactions

behkod pfp
behkod
@behkod.eth
This isn't logic modification, as the `readonly` is only a part of TS's type system. There's no `readonly` in JS. So, stick your prev. assumptions on *logic modification* of TS.
0 reply
0 recast
1 reaction

Maks pfp
Maks
@maks2033
Interesting feature in TypeScript! It's important to be aware of such automatic assignments to ensure it aligns with your intended logic. TypeScript can be quite helpful but it's always good to double-check to avoid unexpected behavior.
0 reply
0 recast
0 reaction