C
Join ServerC#
help
ToastElement
Wwiz11/28/2022
Hello guys,
I am going through a project and found some things not working, this is one of the errors that I could not solve easily by myself as typescript is a greener area for me
Error TS2722 (TS) Cannot invoke an object which is possibly 'undefined'. D:\asd\Web\ClientApp\tsconfig.json
D:\asd\ToastElement.spec.tsx
beforeEach(() => {
wrapper.find(Toast).props().onClose();
});
This is occuring in a ToastElement.spec.tsx file
Best Regards
I am going through a project and found some things not working, this is one of the errors that I could not solve easily by myself as typescript is a greener area for me
Error TS2722 (TS) Cannot invoke an object which is possibly 'undefined'. D:\asd\Web\ClientApp\tsconfig.json
D:\asd\ToastElement.spec.tsx
beforeEach(() => {
wrapper.find(Toast).props().onClose();
});
This is occuring in a ToastElement.spec.tsx file
Best Regards
Wwiz11/28/2022
Let me know if u need more information
AAntonC11/28/2022
that's a typescript nullability warning basically
AAntonC11/28/2022
one of those things in that call chain returns something that can be undefined (basically the same as null)
AAntonC11/28/2022
you need to check for nulls
AAntonC11/28/2022
or use the null forgiving operator
AAntonC11/28/2022
the if-null (?) and null-forgiving (!) work the same way in typescript as in c#
AAntonC11/28/2022
@wiz
Wwiz11/28/2022
Hi, sorry my son was going crazyt
Wwiz11/28/2022
I tried to but couldn't figure out where to place a null check operator
AAntonC11/28/2022
after
find
probablyAAntonC11/28/2022
try splitting it on to multiple lines, and see on which line the error is, if your editor isn't configured for ts
Wwiz11/28/2022
Just turns into this:

Wwiz11/28/2022
The condition will always return true since this function is always defined. Did you mean to call it instead?
Wwiz11/28/2022
And
Wwiz11/28/2022
Property 'props' does not exist on type 'typeof Toast'.
Wwiz11/28/2022
This is not throwing a error

AAntonC11/28/2022
um
AAntonC11/28/2022
that's not how you use that operator
Wwiz11/28/2022
ok
Wwiz11/28/2022
I am used to C#.net, don't have much time in TS.
AAntonC11/28/2022
it's the same in typescipt tho
Wwiz11/28/2022
from what I know u use it before a member
Wwiz11/28/2022
for example .?property
AAntonC11/28/2022
but not before a function name
AAntonC11/28/2022
i mean, after
Wwiz11/28/2022
no
AAntonC11/28/2022
before parameter list
Wwiz11/28/2022
only before param
Wwiz11/28/2022
ye
AAntonC11/28/2022
no, not before parameter list, that's not allowed even in c#
AAntonC11/28/2022
even though hm it might be allowed in ts
Wwiz11/28/2022
I didn't mean in C#, in C# from what I know I only use it before members of objects.
Wwiz11/28/2022
But I am just getting back more into coding, I have been in a integration team for the past 4 years so bit rusty.
AAntonC11/28/2022
put it after calling find
AAntonC11/28/2022
find(Toast)?.whatever
AAntonC11/28/2022
that would make way more sense
Wwiz11/28/2022
ok
Wwiz11/28/2022
Does onClose require a ()?
it is complaining about Cannot invoke an object which is possibly 'undefined'.
it is complaining about Cannot invoke an object which is possibly 'undefined'.
AAntonC11/28/2022
in c# you'd do onClose?.Invoke()
Wwiz11/28/2022
yeah
AAntonC11/28/2022
I don't know how you do that in typescrpt, probably onClose?.invoke(), but you should google this
Wwiz11/28/2022
I was meant to create a health check in a microservice, it span into me finding bunch of undefined and unknown's that was resolved by for example doing this: addFromException(response as any); in other places.
AAntonC11/28/2022
ah you could also adjust the typescipt config
Wwiz11/28/2022
I read about a flag to ignore these kind of errors in the cfg
AAntonC11/28/2022
if you don't really care about those
AAntonC11/28/2022
yeah
Wwiz11/28/2022
suppressImplicitAnyIndexErrors
Wwiz11/28/2022
Which is supposed to be in the ts cfg
Wwiz11/28/2022
I searched through the azure stack but couldn't find it anywhere else so decided to sit and resolve manually.
Wwiz11/28/2022
Now I am starting to think that I am just cluttering the solution.
Wwiz11/28/2022
it was only in 10~ places, but still.
AAntonC11/28/2022
it's either in the typescript config or in the linter config
Wwiz11/28/2022
Can't find a linter config in the solution
Wwiz11/28/2022
but i did find a tsconfig.json
Wwiz11/28/2022
there is a eslintrc.json but it is only warnings
AAntonC11/28/2022
Wwiz11/28/2022
ok, thank you
Wwiz11/28/2022
Now I have a error in Index.d.ts
Severity Code Description Project File Line Suppression State
Error TS2792 (TS) Cannot find module './lib'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? Miscellaneous C:\Users\z\AppData\Local\Microsoft\TypeScript\4.8\node_modules@types\react-bootstrap\index.d.ts 44 Active
Severity Code Description Project File Line Suppression State
Error TS2792 (TS) Cannot find module './lib'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? Miscellaneous C:\Users\z\AppData\Local\Microsoft\TypeScript\4.8\node_modules@types\react-bootstrap\index.d.ts 44 Active
Wwiz11/28/2022

AAntonC11/28/2022
is there a lib file?
AAntonC11/28/2022
ah wait what, error in bootstrap??
AAntonC11/28/2022
you should google this one, really no clue
Wwiz11/28/2022
I am, but after looking through about 10 articles I am not that much smarter