Try to support running with ts-node
See original GitHub issuets-node
does not auto-import types from include
because there’s a notable performance penalty to doing so. As a result when running with ts-node
the types file generated by Nexus’ typegen
option are not available, and thus any custom scalar method or plugin method will result in a type error. And ts-node
still seems to be the de-facto way to run TypeScript in development.
ts-node
does offer a way to support generated TypeScript definitions. By adding a folder to typeRoots
. However for that to work the generated typescript definitions need to be structured as type packages not loose type definition files.
It would be really nice if using Nexus in development would work smoothly with ts-node
without needing to use --files
, manually include the generated types with /// <reference
in every single schema definition file you write, or setup a complex alternative to ts-node
.
I think this might be possible if Nexus generated its type definition files in a type package structure.
I’m not entirely certain how Nexus’ generated types work. But I think it’s possible that the declare global
may not work with the type package structure.
One theoretical alternative I could think of would be to fake something like a @nexus/schema/generated
module. The real @nexus/schema/generated
module file would not export any types, or alternatively it would just re-export the current interfaces that are global declared interfaces so that @nexus/schema
can import them from @nexus/schema/generated
instead of relying on them being global. Then if a project opts-in to typegen exporting a type package instead of a loose type definition file Nexus can generate a {typegenRoot}/@nexus/schema/generated.d.ts
and instead of declare global
Nexus can export things inside of declare module "@nexus/schema/generated"
blocks and this will theoretically override the @nexus/schema/generated
with the generated types that Nexus needs.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
@Weakky had a theory (we never verified) that
node_modules/@types/*
was special cased by and/or VSCode/TS Language Server such that changes under that directory were picked up and affected TS typings state consistently.I’ve definitely seen the issues you’re referring to though. I actually had a rough time the other week on a demo project and it was using
node_modules/@types
in that case. But that was an exception in my experience.So many moving parts and changing versions of tools integrating 🙈.
Im experiencing a similar issue. I have my nexus types being outputted to
node_modules/@types/nexus-typegen/index.d.ts
, and have"typeRoots": ["./typings", "./node_modules/@types"
in mytsconfig.json
, but am not able to reference nexus types such asNexusGenFieldTypes