Can't import module types in Flow library definitions
See original GitHub issueDoes Flow support type imports inside libdefs?
Since Apollo’s graphql-tools doesn’t provide flow types I’m providing my own.
// flow-typed/graphql-tools.js
/* @flow */
import type { GraphQLSchema } from 'graphql'
declare module 'graphql-tools' {
declare export var makeExecutableSchema: ({|
typeDefs: string,
resolvers: { [typeName: string]: { [fieldName: string]: () => mixed } },
|}) => GraphQLSchema
}
Given that graphql
is a peer dependency of graphql-tools
I’m importing GraphQLSchema
from graphql
.
The issue is that when calling makeExecutableSchema
the return type is always any
.
/* @flow */
// `typeof makeExecutableSchema` is `({|resolvers: {[typeName: string]: {[fieldName: string]: () => mixed}}, typeDefs: string|}) => GraphQLSchema`
import { makeExecutableSchema } from 'graphql-tools'
// `typeof schema` is `any`
const schema = makeExecutableSchema({ typeDefs, resolvers })
If instead of GraphQLSchema
I use a builtin type, like number
, there’s no issue.
Is it not possible to import types from other modules when declaring a libdef?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:16 (16 by maintainers)
Top Results From Across the Web
Module Types | Flow
Importing and exporting types. It is often useful to share types in between modules (files). In Flow, you can export type aliases, interfaces,...
Read more >Get type definitions from imported files not marked with @flow
According to the documentation regarding modules: "Flow is able to infer most types in your program for you, but there is one restriction ......
Read more >6. Modules — Python 3.11.1 documentation
Such a file is called a module; definitions from a module can be imported into other modules or into the main module (the...
Read more >Python Modules (With Examples) - Programiz
To import our previously defined module example , we type the following in the Python prompt ... The Python standard library contains well...
Read more >The Module System — Coq 8.16.1 documentation
The names to import may be constants, inductive types and constructors, and notation aliases (for instance, Ltac definitions cannot be selectively imported) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@saadq, ah yes, that is correct!
Question. If the library is a peer dependency, shouldn’t
flow-typed
not care that it’s being imported? What is the reason thatflow-typed
doesn’t support that at the moment?This is now possible with PR’s targeting
main
branch. v4 CLI coming soon but test framework setup and ready to go https://github.com/flow-typed/flow-typed/blob/main/CONTRIBUTING.md#importing-types-from-other-libdefs