-
-
Notifications
You must be signed in to change notification settings - Fork 364
[React] Fix window types #548
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
[React] Fix window types #548
Conversation
tsconfig.json
Outdated
@@ -6,7 +6,7 @@ | |||
"noUnusedLocals": true, | |||
"rootDir": "src", | |||
"strict": true, | |||
"strictPropertyInitialization": false, | |||
"strictPropertyInitialization": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realised I changed this to see if it was raising errors when this is set to true. It might break other packages...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I gonna turn this off later today
if (!this.componentValue) { | ||
throw new Error('No component specified for react controller'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just to solve the unitialized error that Typescript raise when compiling assets, as it seems to be related to stimulus code -- we don't initialise it here but I guess it would in the runtime
|
||
type Component = string | FunctionComponent<object> | ComponentClass<object, any>; | ||
|
||
declare global { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This piece of code is inspired from a StackOverflow example and the Vue example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only part I'm not sure about is how you define the type Component
. But, I think it's pretty safe to use this and if there is a better way, someone will tell us :). This is just to make TypeScript happier. So, I think the worst-case scenario is that someone tells us a nicer way to make TypeScript happier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you. I just looked at how Typescript inferred the type where it is used.
If someone knows a better way, let's use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor tweaks - thanks so much for this!
|
||
type Component = string | FunctionComponent<object> | ComponentClass<object, any>; | ||
|
||
declare global { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only part I'm not sure about is how you define the type Component
. But, I think it's pretty safe to use this and if there is a better way, someone will tell us :). This is just to make TypeScript happier. So, I think the worst-case scenario is that someone tells us a nicer way to make TypeScript happier.
tsconfig.json
Outdated
@@ -6,7 +6,7 @@ | |||
"noUnusedLocals": true, | |||
"rootDir": "src", | |||
"strict": true, | |||
"strictPropertyInitialization": false, | |||
"strictPropertyInitialization": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just commited your suggestions. 😉 Hope that is enough to make it work! I wonder if it would be possible to generate declaration file too as I mentionned in OP |
53db2bc
to
9b43394
Compare
Thanks @AlexandreGerault for the PR and your patience with the merge! About the declaration files, indeed, that would be great to have if I'm understanding the situation correctly. Cheers! |
Hi!
As I discussed with @weaverryan on the Slack, I got an error with the
symfony/ux-react
while using it at work in a Sylius project.Here was the log I had:
To handle errors about
__WebpackModuleApi
I just installed the@types/webpack-env
package.But I still had errors for the
window.resolveReactComponent
function and for thecomponentValue
field.My PR goal is to fix the two type errors. Also I wonder if it is possible to generate (maybe in other PR) the declaration files so that it is compatible with Typescript files without having to use
// @ts-expect-error
(or// @ts-ignore
) when importing the register react controllers function like so: