Skip to content

Commit 0b5a589

Browse files
committed
remove conditional logic for page object type generation
1 parent ed3870b commit 0b5a589

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

lib/command/definitions.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,7 @@ function getImportString(testsPath, targetFolderPath, pathsToType, pathsToValue)
230230

231231
for (const name in pathsToType) {
232232
const relativePath = getPath(pathsToType[name], targetFolderPath, testsPath)
233-
// Page objects and other support modules are exported as plain objects, not as default exports
234-
if (relativePath.endsWith('.ts')) {
235-
importStrings.push(`type ${name} = typeof import('${relativePath}')['default'];`)
236-
} else {
237-
importStrings.push(`type ${name} = typeof import('${relativePath}');`)
238-
}
233+
importStrings.push(`type ${name} = typeof import('${relativePath}');`)
239234
}
240235

241236
for (const name in pathsToValue) {

test/runner/definitions_test.js

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

110-
// Page objects are exported as plain objects, not classes
111-
// So they should not have ['default'] to allow autocompletion
110+
// Page objects are exported as plain objects in .js files
111+
// Use typeof import() without ['default'] to allow TypeScript to infer the object type
112112
extend.should.include("type CurrentPage = typeof import('./po/custom_steps.js');")
113113
assert(!err)
114114
done()

0 commit comments

Comments
 (0)