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

Improve types to understand arrays of arrays #2

Closed
bahmutov opened this issue Oct 12, 2021 · 7 comments
Closed

Improve types to understand arrays of arrays #2

bahmutov opened this issue Oct 12, 2021 · 7 comments
Labels
enhancement New feature or request types

Comments

@bahmutov
Copy link
Owner

it.each([
  [1, 'foo'],
  [2, 'bar']
])('title', (a, b) => {
  // a should be a number
  // b should be a string
})
@bahmutov bahmutov added enhancement New feature or request types labels Oct 12, 2021
lastType added a commit to lastType/cypress-each that referenced this issue Oct 27, 2021
Proposition to solve : Improve types to understand arrays of arrays bahmutov#2 
  [2, 'bar']
])('title', (a, b) => {
  // a should be a number
  // b should be a string
})
@DlgSHi
Copy link
Contributor

DlgSHi commented Mar 24, 2023

@bahmutov Hi Gleb, is any chance to merge this fix? Or introduce types? Thanks in advance

@bahmutov
Copy link
Owner Author

I added an example spec showing the problem. The solution in https://github.com/lastType/cypress-each/pull/1/files solves type check in that example, but breaks every other spec :( if you run npm run lint.

@DlgSHi
Copy link
Contributor

DlgSHi commented Apr 24, 2023

@bahmutov maybe it is because the simple typo ?

(this:Contexte,arg1:any,arg2:any)

instead of

(this:Context,arg1:any,arg2:any)

Context without e

@DlgSHi
Copy link
Contributor

DlgSHi commented Apr 25, 2023

I've tried to apply that change and:
just added new type.

type TestCallback4<T extends readonly any[]> = T extends []
    ? (this: Context, arg1: any, arg2: any) => void
    : Parameters<(...res: [...T, any, any]) => void> extends [...infer R]
    ? R extends readonly [...T, any, any]
      ? (this: Context, ...res: [...R]) => void
      : never
    : never

Applied all other changes suggested, and removed cypress/**/*.js file from type check (why the *.js file should be there?) and it is working as expected :)

@bahmutov
Copy link
Owner Author

bahmutov commented Apr 25, 2023 via email

@DlgSHi
Copy link
Contributor

DlgSHi commented May 8, 2023

Created #75

@bahmutov
Copy link
Owner Author

bahmutov commented May 8, 2023

done

@bahmutov bahmutov closed this as completed May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request types
Projects
None yet
Development

No branches or pull requests

2 participants