Skip to content

Commit fb3ecd2

Browse files
committed
fix logic
1 parent 0b5a589 commit fb3ecd2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/command/definitions.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,15 @@ function getImportString(testsPath, targetFolderPath, pathsToType, pathsToValue)
229229
const importStrings = []
230230

231231
for (const name in pathsToType) {
232-
const relativePath = getPath(pathsToType[name], targetFolderPath, testsPath)
233-
importStrings.push(`type ${name} = typeof import('${relativePath}');`)
232+
const originalPath = pathsToType[name]
233+
const relativePath = getPath(originalPath, targetFolderPath, testsPath)
234+
// For .js files with plain object exports, access .default to allow TypeScript to extract properties
235+
// For .ts files, the default export is handled differently by TypeScript
236+
if (originalPath.endsWith('.js')) {
237+
importStrings.push(`type ${name} = typeof import('${relativePath}').default;`)
238+
} else {
239+
importStrings.push(`type ${name} = typeof import('${relativePath}');`)
240+
}
234241
}
235242

236243
for (const name in pathsToValue) {

test/runner/definitions_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ describe('Definitions', function () {
108108
const extend = definitionFile.getFullText()
109109

110110
// Page objects are exported as plain objects in .js files
111-
// Use typeof import() without ['default'] to allow TypeScript to infer the object type
112-
extend.should.include("type CurrentPage = typeof import('./po/custom_steps.js');")
111+
// Access .default to allow TypeScript to extract properties for autocompletion
112+
extend.should.include("type CurrentPage = typeof import('./po/custom_steps.js').default;")
113113
assert(!err)
114114
done()
115115
})

0 commit comments

Comments
 (0)