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

feat: Add .d.ts files generation on cozy-stack-client #1234

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented Aug 31, 2022

On our Flagship mobile app I need type declaration for client.getStackClient() so I'm trying to add .d.ts files generation on cozy-stack-client like it is already set for cozy-client

There are a lot of TS errors, so this PR may take a bit of time. It is draft for now, so you can help if you want to.

For now:

  • chore commits are only JSDoc related ones, so they should not impact the lib's behaviour
  • feat commits are modifying the code, so the behaviour may be impacted, we should keep our attention on them
  • fix commits are for fixing bugs highlighted by TS-check. My understanding is that current code should not work by construction

@@ -516,7 +516,7 @@ class OAuthClient extends CozyStackClient {
/**
* Updates the client's stored token
*
* @param {string} token = null The new token to use — can be a string, a json object or an AccessToken instance.
* @param {AccessToken|string} token = null The new token to use — can be a string, a json object or an AccessToken instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

can also be null

@@ -21,6 +21,10 @@ export function isSecureProtocol(urlArg) {
export function getBrowserCozyURL() {
try {
const root = document.querySelector('[role=application]')
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

The ts-ignore is only for this block of code, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes @ts-ignore is for the following line. For the entire document we would use @ts-nocheck

@@ -15,6 +15,7 @@ class ShortcutsCollection extends DocumentCollection {
* @param {string} attributes.name Filename
* @param {string} attributes.url Shortcut's URL
* @param {string} attributes.dir_id dir_id where to create the shortcut
* @param {string} attributes.type TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

Should only be empty or io.cozy.files.shortcuts

@@ -16,7 +16,10 @@ const headersFromString = headerString => {
* @private
* @param {string} fullpath - Route path
* @param {object} options - Fetch options
* @param {Function} options.onUploadProgress - Callback to receive upload progress events
* @param {(this: XMLHttpRequestUpload, ev: ProgressEvent<XMLHttpRequestEventTarget>) => any} options.onUploadProgress - Callback to receive upload progress events
* @param {string} options.method - TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if TS comes with built-in type for this, but can be one of those https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

@Crash--
Copy link
Contributor

Crash-- commented Sep 1, 2022

Nice! (cc @acezard since we talk about that recently ;))

@Crash-- Crash-- force-pushed the feat/cozy-stack-client-typedefs branch from 9e1a551 to 928529d Compare September 22, 2022 15:47
@trollepierre trollepierre removed their request for review September 28, 2022 07:49
@Crash-- Crash-- force-pushed the feat/cozy-stack-client-typedefs branch from f72d1cf to eb46bf2 Compare December 9, 2022 13:28
@Crash-- Crash-- marked this pull request as ready for review December 14, 2022 14:20
@Ldoppea
Copy link
Member Author

Ldoppea commented Dec 14, 2022

I can't approve my own PR, but latest changes looks good to me 👍

@Crash-- Crash-- force-pushed the feat/cozy-stack-client-typedefs branch from 7f79c72 to 843fce9 Compare February 9, 2023 09:46
Crash-- and others added 2 commits February 9, 2023 10:56
These types are needed in the native app.
For now I did not find how to make JSDoc understand that
CozyStackClient will inherit OAuthClient methods,
that's the only thing not working for 100% flagship app compat
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.

3 participants