Svish/cypress-helper-getcy

TS2403: Subsequent variable declarations must have the same type

Svish opened this issue ยท 0 comments

Svish commented

When importing useCypressTag or cypressTag into non-cypress files, I get a bunch of TS2403 errors from jest. No clue why, or how to fix it yet... please let me know if you do... ๐Ÿ˜•

The Cypress side of things work great, and everything works fine within this project. So it's only when I try to use the useCypressTag helper function in the application code of a different Typescript project (in a React component of a create-react-app project) ๐Ÿคทโ€โ™‚๏ธ

Workaround

Either just don't use the useCypressTag helper, write your own, or simply copy the following helper function into your own project and import it from there instead of from cypress-helper-getcy.

// E.g. in src/util/useCypressTag.ts

export interface DataCyProp {
  'data-cy'?: string;
}

const combineParts = (...part: (string | undefined)[]): string =>
  part.filter(p => typeof p === 'string').join('/');

export default function useCypressTag(
  ...namespace: string[]
): (name?: string) => DataCyProp {
  if ('Cypress' in window)
    return name => ({
      'data-cy': combineParts(...namespace, name),
    });
  else return () => ({});
}