execa icon indicating copy to clipboard operation
execa copied to clipboard

TypeScript `<3.4` support

Open ehmicky opened this issue 6 years ago • 11 comments

The types do not work with TypeScript 3.3 (see #335) and below notably because of the changes to the readonly keyword brought by TypeScript 3.4. What should we do about it?

  1. Do nothing
  2. Add a typesVersions field to declare that we only support >=3.4
  3. Add a second fallback index.d.ts for lower versions, and use the typesVersions field to distinguish it.

ehmicky avatar Jun 27 '19 17:06 ehmicky

Do nothing.

typeVersions is meant to add fallbacks.

sindresorhus avatar Jun 27 '19 17:06 sindresorhus

Is there a way for us to document our minimal TypeScript supported version?

ehmicky avatar Jun 27 '19 17:06 ehmicky

Not in a way that warns the user I think. We could note it in the readme, but we both know that will not help much.

sindresorhus avatar Jun 28 '19 13:06 sindresorhus

I've done some quick search and it does not seem like TypeScript supports specifying minimal TypeScript version. As you say typesVersions is only meant for fallbacks.

I don't think we can assume users will always use the latest TypeScript version (major+minor+patch). New TypeScript versions are generally mostly compatible with older ones, but they also introduce new features that won't work on older versions.

Should we add a comment on top of the index.d.ts? Many users experiencing issues with tsc will probably look up that file.

I am also going to check if it's among the 3862 opened issues in the TypeScript repo, and post an issue there otherwise.

If there is really no solution to that problem (which I am surprised of), I would consider creating a package to solve it.

ehmicky avatar Jun 28 '19 14:06 ehmicky

Should we add a comment on top of the index.d.ts? Many users experiencing issues with tsc will probably look up that file.

Sure

I am also going to check if it's among the 3862 opened issues in the TypeScript repo, and post an issue there otherwise.

👍

sindresorhus avatar Jun 28 '19 15:06 sindresorhus

Issue at https://github.com/microsoft/TypeScript/issues/32166

Let's see what happens there first.

ehmicky avatar Jun 28 '19 17:06 ehmicky

The guys at TypeScript are saying that supporting a minimal TypeScript version should be specified by using:

  "typesVersions": {
    ">=3.4": { "*": ["index.d.ts"] }
  }

This should produce an error message for users of older TypeScript versions: "'package.json' does not have a 'typesVersions' entry that matches version '3.1'.".

However there seems to be a bug there.

ehmicky avatar Jun 28 '19 17:06 ehmicky

Just got burned by this. We cannot afford to upgrade to 3.4 as there are other changes that break our code. Wish there was some way to simply ignore that index.d.ts and treat package untyped.

In my opinion as much as nicer it makes the code, would be really that bad to replace all readonly with regular ReadonlyArray? It's not like rewriting a whole type declaration. Just wait a bit more before people can catch up. It's quite silly to be forced to 1.x because of TypeScript and missing out tons of bugfixes and features.

Or at least the workaround https://github.com/microsoft/TypeScript/issues/32166#issuecomment-506851601 sounds like another way. Having empty notsupported.d.ts is just close enough to having an untyped package.

danielkcz avatar Jul 29 '19 16:07 danielkcz

I would like @sindresorhus input on this.

I think you meant Readonly<T> not ReadonlyArray<T> since we are using readonly on an interface not an array.

ehmicky avatar Jul 29 '19 16:07 ehmicky

No, I mean for example this line ...

https://github.com/sindresorhus/execa/blob/071a8154f882d13116a6a91d8691ea150de31753/index.d.ts#L116

The readonly StdioOption[] should be ReadonlyArray<StdioOption> to be supported prior TS 3.4.

But yea, there is a need for a bunch of Readonly<T> as well. It has produced 33 errors in total.

danielkcz avatar Jul 29 '19 16:07 danielkcz

Yes sorry you're right. Still would need some feedback from @sindresorhus on this.

ehmicky avatar Jul 29 '19 16:07 ehmicky

TypeScript 3.4 is old now, so we can close this.

ehmicky avatar Mar 09 '23 23:03 ehmicky