apollo-tooling icon indicating copy to clipboard operation
apollo-tooling copied to clipboard

Add typescript support for apollo.config.ts

Open evans opened this issue 5 years ago • 4 comments

Creating a new config with the proper fields is quite burdensome, since the fields allowed are non-obvious and error messaging could be improved. Adding typescript to the apollo config would provide editor completion and an understanding of the acceptable fields/values.

This issue is a feature request for a technical solution, so there may be a better way to accomplish this task, such as a linter

evans avatar Mar 14 '19 23:03 evans

This kinda works but is broken. If one gives apollo.config.ts file with --config option it seems to pick it up but can't really compile. For me causes

Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.

So export = {config} don't work. But neither does export defaults:

The error was: TypeScriptCompileError: Failed to compile TypeScript: Unexpected token 'export'

hixus avatar Aug 11 '20 12:08 hixus

This kinda works but is broken. If one gives apollo.config.ts file with --config option it seems to pick it up but can't really compile. For me causes

Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.

So export = {config} don't work. But neither does export defaults:

The error was: TypeScriptCompileError: Failed to compile TypeScript: Unexpected token 'export'

If you are able to use module: commonjsin project tsconfig it actually works. However I'm not so had to use js file as a config.

hixus avatar Aug 12 '20 07:08 hixus

This could actually be somewhat solved if there is a TS file that exports the schema for the config file. All we need to do is use a JSDoc comment above the config, and it'll apply the type:

/**
* @type {import('from-here').Type}
*/

nandorojo avatar Nov 03 '21 23:11 nandorojo

Actualization this issue with my message. Any plans or updates?

antonfrolovsky avatar Apr 26 '24 16:04 antonfrolovsky