-
-
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, FormDataConsumer, getSource is possibly undefinded #8958
Comments
Besides, we don't have any TS warning in the simple demo (https://stackblitz.com/github/marmelab/react-admin/tree/master/examples/simple?file=src%2Fposts%2FPostEdit.tsx%3AL168) So I'm not sure why you encountered that error. |
@slax57 Sure, here's an example, please take a look, https://codesandbox.io/p/sandbox/gifted-hooks-162e3r?file=%2Fsrc%2FExample%2Findex.tsx%3A18%2C68-18%2C77 |
@PavelTankovich Thanks for the repro. I've played around a bit with it, and it turns out, this is dependent on the TS config in place. I haven't figured out which config property yet, but as soon as you add a {
"compilerOptions": {
"rootDir": "src",
"jsx": "react",
"allowSyntheticDefaultImports": true
},
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js"],
"include": ["src"]
} then the error disappears and the IDE considers the type to be Anyway, I don't see how we could improve the type for now, so the best we could do is mention this gotcha in the documentation. Hence I'll label this as a documentation issue. |
What you were expecting:
I expect the
getSource
function fromFormDataConsumer
not to beundefined
What happened instead:
When I try to use
getSource
fromFormDataConsumer
I get a problem related to ts.TS2722: Cannot invoke an object which is possibly 'undefined'.
Because of this I have to add an extra condition in the code.
Steps to reproduce:
Use
getSource
fromFormDataConsumer
in an application with tsRelated code:
Other information:
Environment
The text was updated successfully, but these errors were encountered: