Why can I use class as type in TypeScript, like word: Word in the code below?
class Dict {
private words: Words = {};
// I wonder about this line
add(word: Word) {
if (!this.words[word.term]) {
this.words[word.term] = word.def;
}
}
}
class Word {
constructor(term: string, def: string) {}
}
I wanted to understand it through official document but couldn’t find related content.
https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
>Solution :
You can do this in most statically typed languages. By annotating word with Word you can access its class properties.
More info:
https://www.tutorialsteacher.com/typescript/typescript-class