Skip to content

Commit ed3870b

Browse files
committed
restore autocompletion for page objects in TypeScript
1 parent 314f46e commit ed3870b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/command/definitions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ function getImportString(testsPath, targetFolderPath, pathsToType, pathsToValue)
230230

231231
for (const name in pathsToType) {
232232
const relativePath = getPath(pathsToType[name], targetFolderPath, testsPath)
233-
// For ESM modules with default exports, we need to access the default export type
234-
if (relativePath.endsWith('.js')) {
233+
// Page objects and other support modules are exported as plain objects, not as default exports
234+
if (relativePath.endsWith('.ts')) {
235235
importStrings.push(`type ${name} = typeof import('${relativePath}')['default'];`)
236236
} else {
237237
importStrings.push(`type ${name} = typeof import('${relativePath}');`)

test/runner/definitions_test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ describe('Definitions', function () {
107107
const definitionFile = types.getSourceFileOrThrow(`${codecept_dir}/steps.d.ts`)
108108
const extend = definitionFile.getFullText()
109109

110-
extend.should.include("type CurrentPage = typeof import('./po/custom_steps.js')['default'];")
110+
// Page objects are exported as plain objects, not classes
111+
// So they should not have ['default'] to allow autocompletion
112+
extend.should.include("type CurrentPage = typeof import('./po/custom_steps.js');")
111113
assert(!err)
112114
done()
113115
})

0 commit comments

Comments
 (0)