flow-typed: Can't import module types in Flow library definitions

Does 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?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 16 (16 by maintainers)

Most upvoted 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 that flow-typed doesn’t support that at the moment?