question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't import module types in Flow library definitions

See original GitHub issue

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?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
miguelollercommented, Apr 2, 2018

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

0reactions
Brianzchencommented, Jul 23, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found