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

Improve error message for users of old TypeScript versions

Open glasser opened this issue 3 years ago • 4 comments
trafficstars

We intend to use some brand-new TS 4.7 features (variance annotations) so let's add https://github.com/sandersn/downlevel-dts to the build process so we can have dts files that work with older TypeScript. We can set up the build script now rather than waiting for 4.7 to be out.

glasser avatar May 12 '22 17:05 glasser

This might not be possible; see #6716. We may just need to bump the requirement to v4.7. For now, adding a note requiring v4.7 to the migration guide, but let's reconsider this before the final release (and make sure other parts of the docs show the required version of TS if we do need it to be 4.70.

glasser avatar Jul 22 '22 19:07 glasser

@glasser Something that can help is making an explicit error for everyone trying to use older TS versions. Sadly TS decided not to implement this feature, so I implemented a workaround in graphql-js: https://github.com/graphql/graphql-js/blob/743f42b6ef6006d35bf9e0b45e3b70d6e9100596/resources/build-npm.ts#L86-L97 It produces an error that looks like this:

node_modules/graphql/NotSupportedTSVersion.d.ts:1:63 - error TS1003: Identifier expected.

1 "Package 'graphql' support only TS versions that are >=4.4.0".

IvanGoncharov avatar Aug 15 '22 18:08 IvanGoncharov

That's a good idea. Unfortunately it looks like it depends on the typesVersions feature which is what I had trouble getting to work here... but maybe getting it work in an error-y way is easier than getting it to actually work.

glasser avatar Aug 15 '22 19:08 glasser

@glasser It should work, since it use an asterisk for the happy path, it shouldn't change TS behavior: https://github.com/graphql/graphql-js/blob/743f42b6ef6006d35bf9e0b45e3b70d6e9100596/package.json#L7-L13

IvanGoncharov avatar Aug 15 '22 19:08 IvanGoncharov

post-RC OK

glasser avatar Sep 27 '22 19:09 glasser

I tried getting this to work with our setup for a bit and didn't make too much progress. TS4.7 has been out for 4+ months at this point anyway.

The sort of error that old TS users will get is:

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:63:35 - error TS1139: Type parameter declaration expected.

63 export declare class ApolloServer<in out TContext extends BaseContext = BaseContext> {
                                     ~~

Hopefully folks searching for it will find this issue and discover that they need to upgrade to TS4.7 (which is also in the migration guide).

glasser avatar Oct 04 '22 21:10 glasser