relay icon indicating copy to clipboard operation
relay copied to clipboard

Missing TS type definition for relay config

Open MarceloPrado opened this issue 2 years ago • 5 comments

Jest offer users typed definitions for their config files:

/** @type {import('jest').Config} */
const config = {
  verbose: true,
};

module.exports = config;

As explained in their docs, you can write your docs in JS and use JSDocs to get type inference. Another approach is to write the config file in TS and directly import the Config type.

Would the Relay team consider offering something similar? It would improve the DX when configuring the compiler. The current approach requires me to open the relay-compiler README to manually ensure I'm using the right options.

MarceloPrado avatar Jun 17 '23 15:06 MarceloPrado

We did have a contribution to our types to add this, but was abandoned.

I'll raise a PR to fix this. Sorry about that, that PR snuck through and didnt notice.

Wondering though, would you @captbaritone be open to have this config file included in the relay-compiler package, or keep things over at DT for now?

maraisr avatar Jun 19 '23 01:06 maraisr

I love the idea, and this is something I would love for us to have. That said, I think there is at least one questions we should answer first:

How can we ensure the types file gets updated every time the compiler itself gets updated?

captbaritone avatar Jun 19 '23 01:06 captbaritone

Yeah I think there is a bigger story here with typescript in general, but at least for today — perhaps we can use the existing config types to codegen the typescript types? If you have ideas, happy yo PoC it.

maraisr avatar Jun 19 '23 01:06 maraisr

To his two flies in one hit than also upload a JSON schema to https://www.schemastore.org/json/ to make VSCode and a bunch of editors autocomplete it. Maybe promote a name for that json config like relay.config.json or something.

EloB avatar Jul 25 '23 07:07 EloB

~It's not released yet, but there's a schema now, added in https://github.com/facebook/relay/pull/4723:~

{
  "$schema": "https://github.com/facebook/relay/raw/9f314a080274960ccd9257b66c47b3c6f3d74956/compiler/relay-compiler-config-schema.json",
  // ...
}

~Never mind, the above currently crashes with unknown field $schema.~

It's released, and it works, and you can also do this:

{
  "$schema": "./node_modules/relay-compiler/relay-compiler-config-schema.json",
  // ...
}

alecmev avatar Jul 24 '24 14:07 alecmev

Fixed by #4724

MarceloPrado avatar Sep 09 '24 21:09 MarceloPrado

The original issue isn't really solved though, right? You now have support for JSON files, but if you're using the JS config loader you still don't have any TypeScript types (unless you generate them yourself based on the JSON schema)

tobias-tengler avatar Sep 09 '24 21:09 tobias-tengler

@tobias-tengler you're right, sorry for closing this. It still makes sense to provide something at the Relay land for JS configs.

MarceloPrado avatar Oct 17 '24 09:10 MarceloPrado