C
C#2y ago
froxerbbq

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
36 Replies
froxerbbq
froxerbbqOP2y ago
Let me know if u need more information
Anton
Anton2y ago
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
froxerbbq
froxerbbqOP2y ago
Hi, sorry my son was going crazyt I tried to but couldn't figure out where to place a null check operator
Anton
Anton2y ago
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 ts
froxerbbq
froxerbbqOP2y ago
Just turns into this:
froxerbbq
froxerbbqOP2y ago
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'.
froxerbbq
froxerbbqOP2y ago
This is not throwing a error
Anton
Anton2y ago
um that's not how you use that operator
froxerbbq
froxerbbqOP2y ago
ok
froxerbbq
froxerbbqOP2y ago
I am used to C#.net, don't have much time in TS.
Anton
Anton2y ago
it's the same in typescipt tho
froxerbbq
froxerbbqOP2y ago
from what I know u use it before a member for example .?property
Anton
Anton2y ago
but not before a function name i mean, after
froxerbbq
froxerbbqOP2y ago
no
Anton
Anton2y ago
before parameter list
froxerbbq
froxerbbqOP2y ago
only before param ye
Anton
Anton2y ago
no, not before parameter list, that's not allowed even in c# even though hm it might be allowed in ts
froxerbbq
froxerbbqOP2y ago
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.
Anton
Anton2y ago
put it after calling find find(Toast)?.whatever that would make way more sense
froxerbbq
froxerbbqOP2y ago
ok Does onClose require a ()? it is complaining about Cannot invoke an object which is possibly 'undefined'.
Anton
Anton2y ago
in c# you'd do onClose?.Invoke()
froxerbbq
froxerbbqOP2y ago
yeah
Anton
Anton2y ago
I don't know how you do that in typescrpt, probably onClose?.invoke(), but you should google this
froxerbbq
froxerbbqOP2y ago
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.
Anton
Anton2y ago
ah you could also adjust the typescipt config
froxerbbq
froxerbbqOP2y ago
I read about a flag to ignore these kind of errors in the cfg
Anton
Anton2y ago
if you don't really care about those yeah
froxerbbq
froxerbbqOP2y ago
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.
Anton
Anton2y ago
it's either in the typescript config or in the linter config
froxerbbq
froxerbbqOP2y ago
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
Anton
Anton2y ago
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.
froxerbbq
froxerbbqOP2y ago
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
froxerbbq
froxerbbqOP2y ago
Anton
Anton2y ago
is there a lib file? ah wait what, error in bootstrap?? you should google this one, really no clue
froxerbbq
froxerbbqOP2y ago
I am, but after looking through about 10 articles I am not that much smarter
Want results from more Discord servers?
Add your server