-
-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved typings compatibility #371
Improved typings compatibility #371
Conversation
…ccessors" typescript v3.7.x creates non-backwards compatible typings for property definitions: attempts to use v3.7.x typings with an earlier typescript version will result in `error TS1086: An accessor cannot be declared in an ambient context.`
make typing compatible with esnext lib, instead of only es2018 lib, by omitting 2nd generics parameter NOTE this changes the TReturn type from undefined to any for es2018, i.e. less restrictive typing
... or define multiple typings in |
I am not in favour of downgrading the TypeScript version, because it will prevent benefiting from bug-fixes and newer features as they are released in future releases. I'd be much happier if we can output different typings for older TS versions using |
OK -- if you want, I can take a look at https://github.com/sandersn/downlevel-dts and open a new PR when I get it to work (or another solution for utilizing |
... fyi:
{
"extends": "../tsconfig-build.json",
"include": ["../lib"],
"compilerOptions": {
"outDir": "./"
}
} then run
but there is almost no configuration possible, e.g. for name/path of tsconfig.json file, source-files etc. Also: this will only fix/modify the the typings for exactly this known property/accessor problem that is: this would be no general solution for backwards compatibility, but only for this specific breaking change |
It might be better for now to just include a custom TS script that does the transformation, similar to the approach here: https://github.com/MattiasBuelens/web-streams-polyfill/blob/779bd151a8d9f457406c4a79c625eb872d480a1c/build/downlevel-dts.js. And when downlevel-dts is mature enough to be configurable, we can replace the custom script. |
looks good: I updated the pull request by
|
Looks great! The Next question is how we can make sure that the typings can be tested, of course. I'd imagine we would need a separate test run of some kind. If you have any ideas that would be great! Did you try the end result? Do you know what the minimum TypeScript version is for the modified typings? |
I checked the results: I do not know, how far down the typings are compatible now, but I could look into it. And yes, As for testing: So asking back:
|
I think if With regards to testing, right now we have It would be good to have a minimum version requirement in the README. Once we can easily run the tests (see above) then I don't really see why we can't just add 10 test targets for all semver-minor TS versions and see which ones break. :-) |
good! |
…el-dts.js script instead
added tests for ensuring typings compatibility by creating temporary projects & installing tsc version and compiling (modified) ts source specified in test/unit/typings-test.ts
I added typings-compatibility test: basically the test copies the existing test case file I have created test cases for typescript versions 3.0.x - 3.7.x (i.e. incrementing the minor version number) -- with 2.9.x or lower it did not compile, or at least not with the typings as they are now. See also the corresponding test case array in For 3.0.x and 3.1.x there are additional requirements: For the later versions, i.e. starting with 3.2.x, the |
... something strange is happening: on Windows the test cases for 3.2.x - 3.4.x run successfully for min. I.e. changing the (I am using I have no idea, why there should be a difference when running this on Windows and on *nix in this case!?! Do you have any idea what could cause this? ... or should I just change the test cases, i.e. the "minimal requirements" for using the library with those typescript versions? |
Update: The release notes for typescript v3.6 indicate that the required typings for the The real question is, why |
... the test fails on one the error message is Error: Command failed: npm install
/bin/sh: npm: not found
at ChildProcess.exithandler (child_process.js:294:12)
at maybeClose (internal/child_process.js:982:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5) so |
Great job so far! Looks like we're almost there? I know Yarn allows multiple versions with aliases, like this Perhaps it's possible to vendor the typescript dependencies? I don't think |
yes, I think it's almost there I still have problems understanding the reason for the specific ... except for this Also looking into the details: Anyway: In that case, I think, we do not really need to run the typings compatibility test on that specific Do you think, that would be acceptable, or needs this test to work in that |
I think it's okay to disable the versioned typings tests via an environment variable for this particular test run. It's there specifically to test Alpine Linux which runs a different libc (musl instead of glibc). |
OK, great -- it should work now I added an environment variable ... but: the reason being that for some reason setting the environment variable (via |
Yeah not all environment variables are forwarded by default, you'd have to match the names with the prefixes in https://github.com/zeromq/zeromq.js/blob/master/script/ci/install.sh#L17. |
One job failed but after a restart everything seems fine. Is it ready to merge do you think? |
in principle, I think it's ready although it may not be a bad idea, to add something to the README w.r.t. the supported should I add a draft for this to the README? |
That would be great! I agree more documentation would be helpful. |
OK, I added some description & requirements for use with But, if you think it's fine, then I would say the PR is ready to be merged |
ZeroMQ.js version: 6.0.0-beta.6
with current configuration,
typescript
v3.7.x is used for compiling which introduces backwards-incompatible typings for propertiesthis PR
uses typescript v3.6.x for compilingprovides backwards compatible typings fortypescript
< 3.6.x via fieldstypes
andtypesVersions
inpackage.json
:backwards compatible typings avoid typing errors
error TS1086: An accessor cannot be declared in an ambient context.
whenzeromq.js
is used in projects that usetypescript
< v3.6.0simplifies type definitions forAsyncIterator
in order to increase typing compatibility:it uses simplified typings for
AsyncIterator
in the backwards compatible typings, i.e. when referenced by projects that usetypescript
< v3.6.0 (see above) the "simple" type definition ofAsyncIterator
of theesnext
lib with one instead of two generics parameters is used (the typgings for >= 3.6.0 still use the typings definition ofAsyncIterator
according toes2018
)the backwards compatible typings are generated with the script
"script/ci/downlevel-dts.js"
(included in this PR)comparing the compiled results between v3.7.3 and v3.6.4, there were no differences in the generated JavaScript code, only in the generated typings, i.e. in the*.d.ts
files, so currently, for the actual executable code, it makes no difference to downgrade totypescript
v3.6.xthe drawback for the 2nd change regardingAsyncIterator
is that the typing becomes less restrictive for targetes2018
, changing theTReturn
type fromundefined
toany
, but I think that in this context it is justifiable when weighing it against increased typings compatibility