Skip to content
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

refactor: Add TypeScript support #1985

Merged
merged 14 commits into from
Aug 14, 2023
Merged

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Jul 28, 2023

Pull Request

Issue

Closes: #1950

Approach

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)

@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title feat: add typescript support feat: Add typescript support Jul 28, 2023
@parse-github-assistant
Copy link

Thanks for opening this pull request!

@dblythy
Copy link
Member Author

dblythy commented Jul 28, 2023

This PR uses allowJS: true to auto-generate d.ts files, however, quite a few issues occur when building types:

Screenshot 2023-07-28 at 1 00 00 pm

And a few more when running test:types:

Screenshot 2023-07-28 at 1 00 34 pm

@dblythy
Copy link
Member Author

dblythy commented Jul 28, 2023

@dplewis I have added you to my repo if you would like to contribute. I'm not sure how we can resolve the typescript issues without making large changes to the codebase. The issue seems to be that one file depends on invalid ts, and when that file is fixed, it depends on another file with invalid ts, and so forth. @mtrezza?

@codecov
Copy link

codecov bot commented Jul 28, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01% ⚠️

Comparison is base (549b7b3) 99.88% compared to head (b3e8d85) 99.88%.

❗ Current head b3e8d85 differs from pull request most recent head bd69ab0. Consider uploading reports for the commit bd69ab0 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha    #1985      +/-   ##
==========================================
- Coverage   99.88%   99.88%   -0.01%     
==========================================
  Files          61       61              
  Lines        6143     6117      -26     
  Branches     1491     1491              
==========================================
- Hits         6136     6110      -26     
  Misses          7        7              
Files Changed Coverage Δ
src/EventuallyQueue.js 100.00% <ø> (ø)
src/LocalDatastore.js 100.00% <ø> (ø)
src/Storage.js 100.00% <ø> (ø)
src/CoreManager.js 100.00% <100.00%> (ø)
src/Parse.ts 100.00% <100.00%> (ø)
src/ParseSession.ts 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dblythy dblythy mentioned this pull request Jul 28, 2023
2 tasks
@dplewis
Copy link
Member

dplewis commented Jul 28, 2023

without making large changes to the codebase

@dblythy I have no problem reviewing large changes. This PR is just syntactic sugar without any functionality.

@mtrezza
Copy link
Member

mtrezza commented Jul 28, 2023

@dplewis I think dblythy was referring to the fact that we want to add TypeScript support incrementally without requiring large parts of the codebase to be converted at once, for the reasons described in #1950.

@dplewis
Copy link
Member

dplewis commented Jul 28, 2023

@dblythy If you ignore test:types what else would be needed to merge this PR as is? As long as the project transcompiles and the tests pass I would count this as Typescript support incrementally.

@mtrezza Thoughts?

@mtrezza
Copy link
Member

mtrezza commented Jul 28, 2023

Can we also have a TS test in the CI that ensures that the parts of the code that are already converted to TS are type-correct? Otherwise we'll have a hard time reviewing the incremental TS PRs.

@dplewis
Copy link
Member

dplewis commented Jul 28, 2023

@dblythy @mtrezza For this to work you need to fix the test suite and treat it like the unit tests. Bypass the Parse module and test against the files themselves. Luckly we already have the test suite from definitely typed

import ParseObject from 'ParseObject';
class GameScore extends ParseObject {
  constructor(options?: any) {
      super('GameScore', options);
  }
}

instead of

import Parse from 'Parse';
class GameScore extends Parse.Object {
  constructor(options?: any) {
      super('GameScore', options);
  }
}

@mtrezza
Copy link
Member

mtrezza commented Jul 28, 2023

I was referring to the CI job that currently fails, the "test:types": "dtslint --expectOnly types", npm script. How can we get dtslint to pass?

@dplewis
Copy link
Member

dplewis commented Jul 28, 2023

@dblythy I only changed Parse.ts and ParseSession.ts. Here are the steps if you want to convert other files.

  • Change file extension to .ts
  • Remove @flow from file if it exists
  • Add file to ./tsconfig.json
  • npm run build:types
  • Fix types
  • Add / enable tests in types/test.ts
  • npm run test:types
  • Compare types to @types/parse

@dplewis
Copy link
Member

dplewis commented Jul 29, 2023

src/Parse.ts is broken so you can't test against it until the entire project is typed correctly

I stand corrected, we can test against Parse.ts but first we need to fix these. We should also consider moving to es6.

Screenshot 2023-07-28 at 7 10 15 PM

@dplewis
Copy link
Member

dplewis commented Jul 30, 2023

@dblythy I used allowJs to generate all the typings available with a ts-no-check to remove warnings. Regenerating the typings would remove the no-check, I set it up to prevent that and allow for incremental regeneration by adding files to tsconfig.

index.d.ts shouldn’t be changed for now as every release will have some typing like DefinitelyTyped

@dplewis dplewis requested a review from mtrezza July 30, 2023 15:21
@dplewis
Copy link
Member

dplewis commented Jul 30, 2023

@mtrezza I think this is ready for review

@mtrezza
Copy link
Member

mtrezza commented Jul 30, 2023

Nice, the checks pass. @dblythy What do you think?

So these are the instructions for incrementally convert to TS? If so, I'll copy them to #1950, so we have that documented for contributors.

index.d.ts shouldn’t be changed for now as every release will have some typing like DefinitelyTyped

What does that mean? Is there anything new we need to consider when reviewing PRs? If so, could you amend the instructions with what not to do, so it also serves as guideline for reviewers?

@dplewis
Copy link
Member

dplewis commented Jul 30, 2023

What does that mean?

To be honest I don't use typescript and never published a typescript package. I don't think users will have to install npm install @types/parse after this code gets release. This is my assumption.

Instructions have been updated.

@mtrezza
Copy link
Member

mtrezza commented Jul 30, 2023

That's good point. We know that @types/parse is currently more complete than our gradual conversion. For developers that probably means an immediate loss of types and IDE auto-complete, if they don't use or cannot use @types/parse anymore. What happens if a package installs the Parse JS SDK with our partial TS conversion and also has the @types/parse package installed? Will one overrule the other? Will there be conflicts? Does @types/parse have to be uninstalled? That's info we should include in the change log when merging this.

@dplewis
Copy link
Member

dplewis commented Jul 30, 2023

We would remove the package from DefinitelyTyped to avoid confusion.

@mtrezza
Copy link
Member

mtrezza commented Jul 30, 2023

Would it make sense to accept TS conversion PRs but not publish the type files on NPM just yet, i.e. not include them in the published npm package, only keep them in the GitHub repo? We could wait until we have reached a good level of TS conversion so that developers won't loose the current level of type coverage so drastically.

@dplewis
Copy link
Member

dplewis commented Jul 31, 2023

so that developers won't loose the current level of type coverage so drastically

Since index.d.ts is copied directly from DefinitelyTyped no coverage is loss. As far as publishing to npm, we should plan for the next major release of the SDK

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; maybe someone else could take a look at this as well before we merge? @dblythy @sadortun @radandevist

@mtrezza mtrezza changed the title feat: Add typescript support feat: Add TypeScript support Aug 6, 2023
@mtrezza
Copy link
Member

mtrezza commented Aug 9, 2023

I think we can leave this open for another 2 days; if there are no opposing reviews we'll go ahead and merge.

@dblythy
Copy link
Member Author

dblythy commented Aug 10, 2023

I'm concerned that the allowJS will allow broken types that will throw issues for developers. An example is that the type mixed (which is compatible with flow) is used throughout.

Also as previously mentioned there are a lot of cases where the types are wrong (optionals are not specified, there's wrong types throughout, etc)

I've also enabled a few of the tests because I think we should at least have a few of them activated if we're going to merge.

Another thing that I've observed, even though the Session file has been renamed to .ts, issues still occur when build is ran, as typescript can't interpret the types from ParseObject.

Screenshot 2023-08-10 at 9 14 26 pm

add tests

Update ParseSession.js

Update ci.yml
@dplewis
Copy link
Member

dplewis commented Aug 10, 2023

I'm concerned that the allowJS will allow broken types that will throw issues for developers.

We should change the title of the PR to Add initial TypeScript support. I purposefully removed types/index.d.ts from the package.json to prevent issues for developers until the we have full TypeScript support.

issues still occur when build is ran, as typescript can't interpret the types from ParseObject.

There are a few reasons why I specifically chose ParseSession to be the first file to convert to TypeScript. It has few functions and the limited dependencies it uses are the most important in the project. Its a good place to start since we are about to go down a typing rabbit hole.

@dblythy
Copy link
Member Author

dblythy commented Aug 10, 2023

Sounds good - apologies, I'll revert my changes

@dplewis dplewis requested a review from mtrezza August 10, 2023 23:15
@dblythy dblythy changed the title feat: Add TypeScript support feat: Add initial TypeScript support Aug 11, 2023
This reverts commit b59b111.
@dblythy
Copy link
Member Author

dblythy commented Aug 11, 2023

LGTM ✅

Thanks @dplewis

@mtrezza
Copy link
Member

mtrezza commented Aug 12, 2023

Great to see this is ready for merge; just one last thing: it's unclear what "initial TypeScript support" is supposed to mean. Instead of adding "initial", if we want to communicate anything specific, we can spell it out in the changelog. I can amend the changelog entry in the commit message, so we don't have to write an unreadably-long PR title. Could someone compose a short sentence what we mean by "initial"?

@dplewis
Copy link
Member

dplewis commented Aug 12, 2023

if we want to communicate anything specific

These are internal changes with no effect on the developers yet. Nothing much to communicate unless to you want to show TS progress through changelogs. We can treat this the same as CI changes.

@mtrezza
Copy link
Member

mtrezza commented Aug 12, 2023

Then this should not be a feat but a refactor PR. I have changed it, and since there won't be any changelog entry I also removed the "initial", since it will only show in the commit history and one can only guess what that could mean anyway.

Please confirm that this is correct and I'll go ahead and merge.

@mtrezza mtrezza changed the title feat: Add initial TypeScript support refactor: Add TypeScript support Aug 12, 2023
@dplewis
Copy link
Member

dplewis commented Aug 12, 2023

@mtrezza LGTM!

@mtrezza mtrezza merged commit 54efcf5 into parse-community:alpha Aug 14, 2023
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.2.0-alpha.5

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Aug 27, 2023
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.3.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Sep 16, 2023
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.3.0-alpha.1

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 4.3.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add TypeScript support
5 participants