After switching from Moment.js to dayJS in my code, Webstorm is now flagging numerous TS2339 errors. While these errors aren't causing any issues with compiling or running the code, they are making it challenging to pinpoint the real errors. Here's an example of code where the error occurs:
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'),
);
}
Here's a snippet from my tsconfig.json
file as well:
{
"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 attempted to add dayJS to both the "types"
and "include"
sections, followed by restarting WebStorm, but the error persisted. I've searched for a solution for over a week, and while this issue seems common, none of the suggested fixes have resolved it.
Lastly, here's the relevant part 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;