I'm a fan of Open Source and have a growing interest in serverless and edge computing. I'm not a big fan of spiders, but they're doing good work eating bugs. I also stream on Twitch.
OK, just glanced at the code quickly, so just a few comments about improving the TypeScript code. 😉
interfaceChildren{[key:string]:Node;}
Can be written using TypeScript's built-in generic Record type.
typeChildren=Record<string,Node>;
For
constructor(publiccharacter:string=''){}
You don't need to specify the string type as it's inferred by the default value ''.
For the type for getText, you can create a type and reuse it instead of using (obj: any) => string; in multiple places. Also you could rewrite this type as
<T>(obj:T)=>string;
And extend T so that it respects some criteria.
For public methods, you don't need to specify the public keyword. It's the default.
For type Words = Word[];, I wouldn't bother with this type. Just use Word[].
I'm a fan of Open Source and have a growing interest in serverless and edge computing. I'm not a big fan of spiders, but they're doing good work eating bugs. I also stream on Twitch.
OK, just glanced at the code quickly, so just a few comments about improving the TypeScript code. 😉
Can be written using TypeScript's built-in generic
Record
type.You don't need to specify the
string
type as it's inferred by the default value''
.getText
, you can create a type and reuse it instead of using(obj: any) => string;
in multiple places. Also you could rewrite this type asAnd extend
T
so that it respects some criteria.public
keyword. It's the default.type Words = Word[];
, I wouldn't bother with this type. Just useWord[]
.😮...
Those are great tips, Nick 👊
Regarding the
public
keyword, I was confused coming from C#, in which access modifiers areprivate
by default 😅 (now I know it's public).And
Words
does seem unnecessary asWord[]
shows the intention (of word being an array type) better 😂.It seems like I need to get used to built-in types from those tips.
Thank you for providing me a way to improve the code-base, Nick.
No problem. Glad to see you're having fun in TypeScript land. 🎡
Thank you for the warm welcome.
It's been fun & need to unlearn what I know first 😉