ToastElement
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
D:\asd\ToastElement.spec.tsx beforeEach(() => { wrapper.find(Toast).props().onClose(); });
This is occuring in a ToastElement.spec.tsx file Best Regards
36 Replies
Let me know if u need more information
that's a typescript nullability warning basically
one of those things in that call chain returns something that can be undefined (basically the same as null)
you need to check for nulls
or use the null forgiving operator
the if-null (?) and null-forgiving (!) work the same way in typescript as in c#
@wiz
Hi, sorry my son was going crazyt
I tried to but couldn't figure out where to place a null check operator
after
find
probably
try splitting it on to multiple lines, and see on which line the error is, if your editor isn't configured for tsJust turns into this:
The condition will always return true since this function is always defined. Did you mean to call it instead?
And
Property 'props' does not exist on type 'typeof Toast'.
This is not throwing a error
um
that's not how you use that operator
ok
Member access operators and expressions - C# reference
Learn about C# operators that you can use to access type members.
I am used to C#.net, don't have much time in TS.
it's the same in typescipt tho
from what I know u use it before a member
for example .?property
but not before a function name
i mean, after
no
before parameter list
only before param
ye
no, not before parameter list, that's not allowed even in c#
even though hm it might be allowed in ts
I didn't mean in C#, in C# from what I know I only use it before members of objects.
But I am just getting back more into coding, I have been in a integration team for the past 4 years so bit rusty.
put it after calling find
find(Toast)?.whatever
that would make way more sense
ok
Does onClose require a ()?
it is complaining about Cannot invoke an object which is possibly 'undefined'.
in c# you'd do onClose?.Invoke()
yeah
I don't know how you do that in typescrpt, probably onClose?.invoke(), but you should google this
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.
ah you could also adjust the typescipt config
I read about a flag to ignore these kind of errors in the cfg
if you don't really care about those
yeah
suppressImplicitAnyIndexErrors
Which is supposed to be in the ts cfg
I searched through the azure stack but couldn't find it anywhere else so decided to sit and resolve manually.
Now I am starting to think that I am just cluttering the solution.
it was only in 10~ places, but still.
it's either in the typescript config or in the linter config
Can't find a linter config in the solution
but i did find a tsconfig.json
there is a eslintrc.json but it is only warnings
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
ok, thank you
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
is there a lib file?
ah wait what, error in bootstrap??
you should google this one, really no clue
I am, but after looking through about 10 articles I am not that much smarter