E
E
Eugene2019-12-19 01:12:07
MySQL
Eugene, 2019-12-19 01:12:07

How to initialize an empty variable?

When a function is called, the variable is initialized, but the value is assigned to it later. This causes ts to throw an error. If I specify an alternative type sheets_v4.Sheets | undefined, then in the future, when calling the client properties, an error occurs again, because undefined cannot have properties.

let client: sheets_v4.Sheets
// ....
client = ...


Property 'client' has no initializer and is not definitely assigned in the constructor

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Multigame, 2019-02-07
@Multigame

I would move
JOIN users S on S.id=IF(93=sender_id, sender_id, recipient_id)
JOIN users R on R.id=IF(93=recipient_id, sender_id, recipient_id)
Logic of these ifs from request to processing...

V
Vitsliputsli, 2019-02-07
@Vitsliputsli

JOIN users S on S.id=IF(93=sender_id, sender_id, recipient_id)
JOIN users R on R.id=IF(93=recipient_id, sender_id, recipient_id)

In my opinion the first IF will always give 93 and it makes no sense.
Check the query plan, for some reason it seems to me that the optimizer will incorrectly analyze ambiguous join conditions, due to the fact that in different situations you need to select different indexes, it will most likely prefer full scan. But you need to check.
I would still connect by an unambiguous condition, and already make the conclusion conditional, through CASE.

R
Robur, 2019-12-19
@you_are_enot

let client
// ....
client = ...

client will be of the type assigned to it.
But apparently your client is a property of the class - you need to either initialize it in the constructor, or write | undefined, because there really can be undefined
If you are completely sure that before any use in the client class will be initialized,
then you take responsibility and if everything falls apart and falls because there will be undefined - the typescript is not to blame.

A
abberati, 2019-12-19
@abberati

Well, in your variable there is either some type, or a union from this type and undefined. Initialize immediately with a value. If this is not possible, then you will have to do checks, then it is strict static typing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question