Enable typing for NovaGraphQL interface
ionmorozan opened this issue · 3 comments
With nova/react version 0.3.5, Midgard started throwing errors during linting. One example is NovaGraphQL
interface which accepts GraphQLDocument
of types any
.
File: nova-graphql.interface.ts
export interface NovaGraphQL<GraphQLDocument = any> {)
Use case example:
return (
<HighlightsContextProvider
hostAppCallbacks={hostAppCallbacks}
logger={logger}
highlightsFragment={highlights_highlightFragment}
>
<NovaGraphQLProvider graphql={novaGraphQL}> // this throws errors during linting
{props.children}
</NovaGraphQLProvider>
</HighlightsContextProvider>
);
yarn lint
reports:
ERROR: 87:8 no-unsafe-any Unsafe use of expression of type 'any'.
ERROR: 89:9 no-unsafe-any Unsafe use of expression of type 'any'.
Info on the error: https://palantir.github.io/tslint/rules/no-unsafe-any/
TSLint is configured with:
{
"extends": ["@1js/linting"],
"rules": {
"no-unsafe-any": true
}
}
A workaround is to tag the codeblock with // tslint:disable: no-unsafe-any
Further testing, builds a theory that the issue comes from one of the the latest changes : #22. The d.ts
files generated, for example nova-centralized-commanding-provider.d.ts
imports React.FunctionComponenta
type which is not available.
PS G:\1js\midgard\node_modules\@nova\react\lib> node -e "console.log(require.resolve('@types/react'))"
internal/modules/cjs/loader.js:892
throw err;
^
Error: Cannot find module '@types/react'
React.FunctionComponent
comes from @types/react (index.d.ts) which is not mentioned as a dependency inside nova/react.
It should be listed as peer dependency indeed to make it explicit, which means it does not automatically get installed but that should also not be a problem as the user already installs it (if they use React and TS).
I’m confused about how it technically broke, though. The types package must have been installed in node_modules in either case, so why would it not get picked up? 🤔Something more nuanced must be going on.
We can close this now, all @types/react
is declared as peer dependency and we haven't experienced issues in 1JS as long as one install peer dependencies (we use strict package manager so package owners need to make sure of that)