fd14b4a172
TS type assertions need to be avoided. The following trivial example demonstrates why ``` type Person = { name: string; isBad: boolean; }; function makePerson(): Person { const p: Person = {name: 'whatever'} as Person p.isBad = false return p // theoretically we are now good, p is a Person } ``` Should the type ever change though, TS will happily trot along ``` type Person = { name: string; isBad: boolean; omgHowCouldYou: number; }; function makePerson(): Person { const p: Person = {name: 'whatever'} as Person p.isBad = true return p // p is *not* a Person, omgHowCouldYou is missing } ``` But we pinky swore to the compiler that p is in fact a Person. In other words, the types are now wrong and you will fail during runtime. |
||
---|---|---|
.. | ||
command-line | ||
models | ||
plugins | ||
types | ||
client.ts | ||
clientManager.ts | ||
config.ts | ||
helper.ts | ||
identification.ts | ||
index.d.ts | ||
index.ts | ||
log.ts | ||
server.ts | ||
tsconfig.json |