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

Add TypeScript definitions with JSDoc #7335

Closed

Conversation

mtrezza
Copy link
Member

@mtrezza mtrezza commented Apr 11, 2021

New Pull Request Checklist

Issue Description

Currently, Typescript definitions are maintained via DefinitelyTyped which is:

  • not compatible when distributing Parse Server / Parse JS SDK concurrently via multiple distributions channels
  • a manual effort that should be automated
  • simply tedious

Related issue: #7334

Approach

Add typescript compiler to create TS definitions from JSDoc.

Run npm run types to create types in ./types/.

Notes:

  • TS definitions in Parse JS SDK have to be addressed in the respective repo.
  • TS compiler required refactoring of src/Adapters/Auth/OAuth1Client.js

TODOs before merging

  • Add TS compiler run to CI and build / release process
  • Adapt TS compiler setting to only generate relevant TS definitions
  • Improve quantity and quality of JSDoc annotataions
  • Add entry to changelog
  • Add changes to documentation (guides, repository pages, in-code descriptions)

@mtrezza mtrezza marked this pull request as draft April 11, 2021 00:04
@mtrezza mtrezza changed the title Add typescript generation Add TypeScript generation Apr 11, 2021
@dblythy
Copy link
Member

dblythy commented Apr 11, 2021

It seems to me that from the type files generated, that this wouldn't provide much benefit from a Parse Server developing perspective.

This is the problem I experienced when I tried to automate the types. Although this will work, it doesn't really add much value / enforce the specific options, such as req.user, req.master, etc.

For example, the automated definition for Parse.Cloud.define:

export function define(functionName: any, handler: any, validationHandler: any): void;

Compare that to the manual current definition:

interface FunctionRequest<T extends Params = Params> {
  installationId?: string;
  master?: boolean;
  params: T;
  user?: User;
}
interface ValidatorField {
  type?: any;
  constant?: boolean;
  default?: any;
   options?: any[]|Function;
  error?: String;
}
interface ValidatorFields {
  [field: string]: ValidatorField;
}
interface Validator {
  requireUser?: boolean;
  requireMaster?: boolean;
  validateMasterKey?: boolean;
  skipWithMasterKey?: boolean;
  requireAnyUserRoles?: String[]|Function;
  requireAllUserRoles?: String[]|Function;
  fields?: ValidatorFields|String[];
  requireUserKeys?: ValidatorFields|String[];
}
function define(name: string, func: (request: FunctionRequest) => any, validator?: Validator|((request: FunctionRequest) => any)): void;

In terms of a user perspective, the two most critical components are obviously that the Parse Server Config in index.js is correctly typed (which again, the types generated for ParseServer constructor allows for any), as well as the usage of Parse.Cloud, Parse.Query, etc.

Which to me, would seem that this repo would need a typescript definition for ParseServer, and the JS SDK would handle all the other types, such as Parse.Cloud.define. Any other typescript definitions would be for the benefit of future contributors, which would be an improvement, but not as critical in terms of user usage.

@mtrezza
Copy link
Member Author

mtrezza commented Apr 11, 2021

This is just a proof of concept that the generation works based on JSDoc.

Updating the JSDoc would solve this, we can define interface types and get to exactly what the manual types currently are. That is why I think this approach of decoupling flow from TS and only use JSDoc would be an easy way to go, and eventually allow us gradually implement TS in the repo without any interference.

But I am curious to see the flow-to-ts PR and see which one makes more sense.

@dblythy
Copy link
Member

dblythy commented Apr 11, 2021

Cool, sounds good to me. Does this means that definitions will move away from Flow and instead by TS?

@mtrezza
Copy link
Member Author

mtrezza commented Apr 11, 2021

Yes, but that is a different topic, see point (3) in the larger discussion. This PR is about point (2) and point (1) which seems unnecessary to me is currently being discussed.

@mtrezza mtrezza changed the title Add TypeScript generation Add TypeScript definitions with JSDoc Apr 12, 2021
@mtrezza
Copy link
Member Author

mtrezza commented Apr 12, 2021

Closed in favor of #7337.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants