-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 types are generated with unsafe types because strictNullChecks is false #9622
Comments
Hi, and thanks for your report. We're well aware of the limitations caused by You're welcome to contribute small PRs fixing types of individual hooks & components for strict null checks. I'm closing this issue as it's a long-term goal. |
Thanks for letting us know it's a long term goal. It's not possible to fix the issue with the hooks until strictNullChecks is enabled. It's currently not possible to use the generated types safely in projects. |
@fzaninotto What sort of approach would be required to get strictNullChecks enabled? It looks like someone tried to help you with it in #8141, but because the scope of the change was too big the PR was closed. I'm not sure how you could partially add strict null checks to make for a smaller PR that would be accepted. The benefit is quite high for people using React Admin as it will catch a lot of runtime errors at compile time. |
Here is the process I suggest:
This way, we can gradually make the types better. It will take several PRs to fix the core. This improvement will only be made available for users once we have all the checks fixed. But that's the only safe way. |
Here is an exemple small PR fixing the ra-core types: #9644 |
What you were expecting:
With this code the type of
record
should beMyRecord | undefined
:What happened instead:
The type of
record
isMyRecord
.Steps to reproduce:
Other information:
This issue is caused by the
tsconfig.json
in the base react-admin project not using strict mode, specificallystrictNullChecks
. This means TypeScript will coalesce a type likeRaRecord | undefined
intoRaRecord
. See https://www.typescriptlang.org/tsconfig#strictNullChecksA previous bug was recorded #7588 and fixed in PR #7498. The fix is correct if strictNullChecks is used, but because TypeScript is not configured to consider undefined, the fix doesn't actually do anything.
To confirm this, you can check the build output in either the esm or cjs folders. The
| undefined
is omitted from the generated types.Environment
The text was updated successfully, but these errors were encountered: