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

Browser: Convert all Array to [] #1593

Open
inancgumus opened this issue May 20, 2024 · 0 comments
Open

Browser: Convert all Array to [] #1593

inancgumus opened this issue May 20, 2024 · 0 comments
Labels
Area: browser The browser module

Comments

@inancgumus
Copy link
Member

inancgumus commented May 20, 2024

As discussed here, we want to convert all Array signatures to [] in the k6-browser docs.

It is common to use simple array types in typescript, i.e. Cookie[], for named types:

let a: string[]
let b: boolean[]
let c: SomeInterface[]

The generic version is usually reserved for more complex types, where the brackets might be easy to miss due to the amount of symbols:

let a1: Promise<({ prop: boolean })[]>
// vs.
let a2: Promise<Array<{ prop: boolean }>>

let b1: Promise<(typeof myVal)[]>
// vs.
let b2: Promise<Array<typeof myVal>>

Ups

  • Promise<Inner[]> is easier to read than Promise<Array<Inner>>. The eye does not need to match opening and closing braces.
  • The bracket syntax is ubiquitous in programming, whereas generics are an advanced feature and the syntax is more varied.

Downs

  • Slightly mismatching with PW (i.e., see this). However, improved readability outweighs being consistent with PW's docs. It also appears to be a convention we've used in the type definitions.
@inancgumus inancgumus added the Area: browser The browser module label May 20, 2024
@inancgumus inancgumus self-assigned this May 20, 2024
@inancgumus inancgumus removed their assignment May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: browser The browser module
Projects
None yet
Development

No branches or pull requests

1 participant