0

In my custom types I wish to make use of the GraphQLSchema from the graphql module. If I just write:

interface MyThing {
  schema: GraphQLSchema
}

It does not reference the GraphQLSchema definition from the module (it's just any). VSCode then suggests to auto add the import file:

import { GraphQLSchema } from 'graphql'

The definition is now correct (i.e. hovering above it in VSCode pops the correct type) but now my custom type file no longer works - i.e. I cannot use MyThing in my code - it's no longer defined.

My tsconfig does include my custom typings as well as node_modules/@types - vscode seems to see it so I assume it's fine. I did try specifically adding the path to the graphql file containing the definition but no go.

I am able to use other definitions that are namespaced just fine without an import - just not that one.

Suggestions?

cyberwombat
  • 38,105
  • 35
  • 175
  • 251
  • See https://stackoverflow.com/questions/42233987/how-to-configure-custom-global-interfaces-d-ts-files-for-typescript?noredirect=1&lq=1 – Dario Fiore Oct 31 '20 at 21:22
  • They mention not using `import` in the definition files which is my problem but no answer that I can see on how to solve this? – cyberwombat Oct 31 '20 at 21:30

1 Answers1

0

Ok - prob pretty obvious to experiences TS but wasn't to me. If there is an import statement then everything must be explicitly exported. I didn't have export statements in my file since TS didn't seem to care but I guess the moment you add an import then all must be exported.

Works (but no way to import)

interface MyThing {
  schema: any
}

Does not work

import { GraphQLSchema } from 'graphql'
interface MyThing {
  schema: GraphQLSchema
}

Works with imports

import { GraphQLSchema } from 'graphql'
export interface MyThing {
  schema: GraphQLSchema
}
cyberwombat
  • 38,105
  • 35
  • 175
  • 251