Closed quantuminformation closed 5 years ago
Found our issue: they type object was not accepting another type,
isInitialValid?: boolean | ((props: object) => boolean | undefined);
So we changed our code from a specific type to any
isInitialValid: (props: Foo) => (props.user ? !isEmpty(props.user) : false),
to
isInitialValid: (props: any) => (props.user ? !isEmpty(props.user) : false),
Thanks for the update, @QuantumInformation. Can we close this off?
Soon, I'm just wondering why this error only occurs with the new native CRA. I will also discuss with Formik.
Different projects can have different .tsconfig
files - so this is likely a matter of strictness. But I haven't had a look through in detail at the config in create-react-app-typescript
.
Moving to any
doesn't seem right though... If you can put together a test repository, I could take a deeper look.
We moved the same tsconfig in place of the one generated by the native CRA and had the same error. If we can't resolve it by using any or smth else, will try recreate it for you, thx.
So we can't assign a custom type interface to an object
type now?
@QuantumInformation You certainly can assign custom interfaces/types to objects, I was just agreeing that (as you pointed out) any
didn't seem like the right fix to your problem.
OK, thanks. That certainly shouldn't cause an issue in CRA, it may be the expected type that's the issue... but again, I can't tell you without seeing a live example sorry.
I think the problem is that the typing info of our custom prop, is not being passed on downstream, so consumers of this prop are expecting an object with no custom props.
Hence
` Property 'someProp' is missing in type '{}'. TS2345z
Can you try setting skipLibCheck
to false
in your tsconfig.json
?
Same error remains
"module": "esnext",
"target": "es5",
"lib": [
"es5",
"es6",
"es7",
"es2017",
"dom"
],
"sourceMap": true,
"allowJs": true,
"jsx": "preserve",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"skipLibCheck": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"strict": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
Oops, I'm sorry, I meant try setting it to true
. 😄 Or was it true previously?
Did you eject Create React App? Please paste the contents of tsconfig.json
after running npm start
at least once.
Yes it was true before
We didn't eject and have no plans too
If we use cra generated config, we have same issue, we are worried its a babel thing now.
{
"compilerOptions": {
"target": "es5",
"allowJs": true,
"skipLibCheck": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"lib": ["es2018", "dom"]
},
"include": ["src"]
}
All type validation is performed with TypeScript, Babel does not perform any type checks.
This is most likely a real issue that was just suppressed in CRA-TS. If you provide a reproducing demo we can probably help more.
@QuantumInformation @Timer sounds like this issue stems from not being able to configure CRA's typescript linting –– not sure if it would be useful in this instance, but I'd encourage you to check out Rescripts and the use-tslint-config rescript. Using these two packages, you can configure the linting to be as strict or lenient as you so choose 👍I just released Rescripts and am looking for feedback, so please let me know if there's a specific "rescripts" (like a rewire or plugin) that I could make for you :)
Its probably a side effect of a deeper issue, we will need to port our code over gradually to find some nested TS issue.
This error did not occur anywhere in our app when using the create-react-app-typescript
Any ideas what difference could cause this with the native TS support?