I've recently refactored my code to use dayJS rather than Moment.js, and now Webstorm is reporting a ton of TS2339 errors. These errors aren't preventing my code from compiling or running, but it is making it extremely hard to find actual errors. Here's an example of some code where the error shows up:
export function verifyCreatedDate(date: string) {
cy.log('Verify item creation date');
cy.get('[data-cy="timeline-date"]').should(
'have.text',
Cypress.dayjs(date).format('MM/DD/YY'),
);
}
And here's my tsconfig.json
file:
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": false,
"module": "es2015",
"target": "es2015",
"jsx": "react",
"allowJs": true,
"types": ["cypress", "@percy/cypress"],
"moduleResolution": "node",
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"]
},
"include": ["**/*.ts", "node_modules/cypress/types/mocha/index.d.ts"]
}
I've tried adding dayJS to both the "types"
and "include"
sections, then restarting WebStorm, but that didn't fix the error either. I've been searching for answers for this for about a week, and although this is a common issue, none of the proposed solutions I've found have worked.
Finally, here's the relevant portion of my support/index.js
file:
// if multiple specs need to use dayjs import it in the support file
// and add to the global Cypress object
const dayjs = require('dayjs');
Cypress.dayjs = dayjs;