fix: update TypeScript support and type definitions#147
fix: update TypeScript support and type definitions#147pvlugter merged 6 commits intolightbend:mainfrom
Conversation
9d51dcd to
7c23e9b
Compare
|
Also resolved the remaining warnings from tsd-jsdoc. |
|
@pvlugter first of all thanks for the effort to fix the broken types! 💪 In my opinion our current mixed approach to generate the types makes really hard to get things done correctly. By mixed approach I mean the following
So we are using 3 different ways to generate the TS types. I think the outcome is something what is quite chaotic and hard to understand and maintain, on the other hand breaks very easily. It somehow also gives the false assumptions that the generated types are correct, but I've looked into the To verify these errors please run the following commands: So although the new TS TCK passes, there will be some type errors in the released library, that's why I think our publishing process should include those two commands mentioned above, to make sure that we won't release broken types from now on. Regarding the TCK, I was thinking if wouldn't be enough to have only one version of it, which is written it TS? Based on my concerns, my suggestion would be the following:
If for some reason we want to keep the current mixed approach, we should at least make sure that we only emit the To make this work the and the To help you to fix the broken Since it's a pretty long comment with lot of thoughts, we could have a direct feedback loop with each other to discuss the details, ping me Slack whenever it works for you. |
Right. I haven't changed the approach at all, just looked to have more of the types covered, and checking usage from a project. The plan is still to migrate fully to TypeScript, so we just want something in the interim that works too.
Sounds good. Good if we can verify the types easily.
Yes, let's do that. I may not keep this PR as ongoing, but set that up later. The proxy also depends on the TCK implementation here (as a docker image) for integration tests.
Won't we be missing some types at the top-level, for those parts that are converted to TypeScript already? Or do we add just jsdoc to cover those as well? I'm not that familiar with JS or TS, but I think a mixed approach is fine while we're still migrating over to TypeScript, providing there are ways to make it work out.
Sounds good.
Yep, let's follow up with that.
I don't think we want to continue with a mixed approach for long, just while we're still to migrate everything to TypeScript. Tidying this up sounds good.
I think
Ok, let's follow up separately.
Yes, we certainly still want API docs. I'm assuming that we'll be using tsdoc instead once we've fully migrated to TypeScript. While going through the migrating, if we can keep jsdoc comments and the API docs intact, that would be good.
I don't want to work on one continuous PR for all the TypeScript support, so let's move these into separate issues to follow up on. I think we want to focus on getting to fully TypeScript to make everything easier, but useful if we can keep types and API docs working during the transition. I'm also working in other areas, so suggest that we merge this PR and build on it. |
330d3b3 to
49ff2f5
Compare
|
Have replaced the JavaScript implementation of the TCK with the new TypeScript implementation now. |
|
#135 also updates the TCK for replicated entities. Either that PR or this one will need to be updated, depending on which is merged first. |
janory
left a comment
There was a problem hiding this comment.
Thanks for taking the time to react to my comments and change the PR accordingly. 🙏
I think what we have achieved here is really great improvement and gives us a good migration path (and more confidence) for the rest of the code in the future. 💪
Nothing to fix in this PR, but after npm install I've realised that the package-lock.json got regenerated.
I've created a ticket for this issue: #154
| source /opt/circleci/.nvm/nvm.sh | ||
| pushd sdk && nvm install && npm ci && npm pack && popd | ||
| pushd tck && nvm install && npm install && npm ci && npm run tck && popd | ||
| pushd tck && npm install && npm run tck && popd |
There was a problem hiding this comment.
| pushd tck && npm install && npm run tck && popd | |
| pushd tck && npm ci && npm run tck && popd |
There was a problem hiding this comment.
Can't be npm ci because the package-lock.json is not committed. This was removed/ignored for the TCK a while back — I think because the dependency on the package is in the package.json and these end up conflicting with cached sha hashes each time it gets rebuilt locally.
| node_modules | ||
| .DS_Store | ||
| .idea | ||
| tck/package-lock.json |
There was a problem hiding this comment.
Why do we want to ignore this?
Keeping the package-lock.json makes sure that the dependency resolution is consistent and running the same code always gives back the same results.
There was a problem hiding this comment.
Not completely sure, but I think it was because the dependency to the sdk in the package.json is now directly to the package (tgz file), and the sha for this keeps changing and causing issues. I certainly got those problems in this PR in CI on the first builds. I think it used to link to the sdk directory, but now uses the package.
There was a problem hiding this comment.
Ahh got it.
Yeah, unfortunately we won't be able to keep the package-lock.json if the hash of the sdk is always dynamically changing with each build.
There is only one solution what comes to my mind:
We could use husky to create a pre-commit hook which always packages the sdk before a commit and uses the new hash to monkey patches the package-lock.json.
But it would the actual commit would generate a new outgoing change and it slows things down, so I am not sure that this is the right answer to our problem. It feels very dirty.... 😬
Apparently others had this problem as well: npm/cli#517 🤷♂️
But this is not strictly related to this PR, so nothing what we would need to solve here.
|
@janory, I've implemented your suggestion of only having tsd-jsdoc generate the types. See 8cd6928. This reintroduces some jsdoc comments that were removed when files were converted to TypeScript, and extends to cover the user-facing types properly. These are added to The advantage is that we get the API docs back for the converted parts. We also have all the types in the index definition file again. The disadvantage is that these types are duplicated for the TS files. And we'll need to maintain these doc comments for now, but shouldn't be a problem if we don't change them much while we're still transitioning. |
janory
left a comment
There was a problem hiding this comment.
@janory, I've implemented your suggestion of only having tsd-jsdoc generate the types. See 8cd6928.
This reintroduces some jsdoc comments that were removed when files were converted to TypeScript, and extends to cover the user-facing types properly. These are added to
*.jsdocfiles (alongside each converted TS file) which are only used for generating the API docs andindex.d.ts. No other TS definition files are generated now. And the doc comments in the TS files have been converted to TSDoc format, so we can use a TypeScript API docs generator once we've fully migrated over.The advantage is that we get the API docs back for the converted parts. We also have all the types in the index definition file again. The disadvantage is that these types are duplicated for the TS files. And we'll need to maintain these doc comments for now, but shouldn't be a problem if we don't change them much while we're still transitioning.
@pvlugter this is truly an awesome job!
I am happy that you eventually decided against the mixed approach, because we gained back some valuable JSDoc comments and now with the verify-types command we can make sure that we won't break the exposed types accidentally! 👍
I agree that the maintenance should be a big issues, since we are not changing the SDK or introducing new types, but migrating existing logic to TS which shouldn't affect the JSDoc comments too much.
| "copy-files": "cp -r ./proto ./dist && cp index.d.ts ./dist", | ||
| "compile": "tsc && npm run copy-files", | ||
| "prepack": "npm run compile", | ||
| "compile": "tsc --declaration false --composite false && npm run copy-files", |
There was a problem hiding this comment.
Since we don't need two versions of the tsc command anymore, we can move the declaration and composite flags to the tsconfig.json config file.
Refs https://github.com/lightbend/akkaserverless-framework/issues/689. Fixes #134.
Add a TypeScript implementation of the TCK to test types. Updated for some missing or broken type declarations when going through this. The types for replicated entities still need some additional work.