Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript issue after upgrading to v4 (.1) #271

Closed
OracPrime opened this issue Jan 5, 2021 · 7 comments
Closed

Typescript issue after upgrading to v4 (.1) #271

OracPrime opened this issue Jan 5, 2021 · 7 comments

Comments

@OracPrime
Copy link

I have a react component class using dotnetify. To avoid getting too far behind, I've upgraded dotnetify to 4.1, and typescript has started complaining. My component has a vm member, which I have changed to IDotnetifyVM from the old dotnetifyVM; this is fine. However when I try to initialise it with

this.vm = dotnetify.react.connect('vmname',this)

then I get a warning that react may be undefined and need to use

this.vm = dotnetify.react!.connect('vmname',this)

instead. This seems to be a messy workaround (although clearly not the end of the world). Is there a preferred way of doing it? I had a guess at this.vm = dotnetify.connect('vmname',this) but that fails to hook up the events.

What's the "preferred" way of doing this now in a typescript world?

@dsuryd
Copy link
Owner

dsuryd commented Jan 5, 2021

You shouldn't have to add the ! operator. Take a look at a typescript example here: https://github.com/dsuryd/dotNetify/tree/master/Demo/React/HelloWorld.WebPack

@OracPrime
Copy link
Author

If you enable "strictNullChecks": true, in your tsconfig.json then you get

[tsl] ERROR in C:\github\dotNetify\Demo\React\HelloWorld.WebPack\src\HelloWorld.tsx(14,5) TS2532: Object is possibly 'undefined'.

I suspect increasing numbers of typescript devs will want strictNullChecks.

@dsuryd
Copy link
Owner

dsuryd commented Jan 6, 2021

Thanks. I'll put in the backlog for supporting the strictNullChecks flag in future release.

@OracPrime
Copy link
Author

I was struggling to understand (from my massively distant understanding of your code) why dotnetify.connect couldn't/didn't work. Surely the codebase knows which flavour it is running?

@dsuryd
Copy link
Owner

dsuryd commented Jan 7, 2021

The intent for dotnetify.connect is to support other frameworks that are not explicitly supported (for example, Angular). But you may be right, there's a problem with the code. It could've been broken after Typescript conversion. So thanks again for pointing out these issues. Keep'em coming :)

dsuryd pushed a commit that referenced this issue Jan 8, 2021
@dsuryd
Copy link
Owner

dsuryd commented Jan 8, 2021

Should be resolved with v4.1.1.

@dsuryd dsuryd closed this as completed Jan 8, 2021
@OracPrime
Copy link
Author

OracPrime commented Jan 8, 2021

Excellent, thank you. I can confirm that 4.1.1 allows me to write the code I expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants