Skip to content

Commit 664de16

Browse files
Copilotkobenguyent
andcommitted
Fix auto-suggestion issue for I actor when no helpers configured
When no helpers are configured, the Methods interface was not being generated, causing TypeScript to fail resolving the type referenced in interface I. This broke auto-completion for the I actor methods. The fix ensures that the Methods interface is always generated, even when empty, so that 'interface I extends WithTranslation<Methods>' always references a valid type. Co-authored-by: kobenguyent <[email protected]>
1 parent 4324306 commit 664de16

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

lib/command/definitions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const getDefinitionsFileContent = ({ hasCustomHelper, hasCustomStepsFile, helper
4141

4242
const importPathsFragment = importPaths.join('\n')
4343
const supportObjectsTypeFragment = convertMapToType(supportObject)
44-
const methodsTypeFragment = helperNames.length > 0 ? `interface Methods extends ${helperNames.join(', ')} {}` : ''
44+
const methodsTypeFragment = helperNames.length > 0 ? `interface Methods extends ${helperNames.join(', ')} {}` : 'interface Methods {}'
4545
const translatedActionsFragment = JSON.stringify(translations.vocabulary.actions, null, 2)
4646

4747
return generateDefinitionsContent({
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference types='codeceptjs' />
2+
type MyHelper = InstanceType<typeof import('./myhelper_helper.js').default>;
3+
4+
declare namespace CodeceptJS {
5+
interface SupportObject { I: I, current: any }
6+
interface Methods extends FileSystem, MyHelper {}
7+
interface I extends WithTranslation<Methods> {}
8+
namespace Translation {
9+
interface Actions {}
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const config = {
2+
tests: './*_test.js',
3+
timeout: 10000,
4+
output: './output',
5+
helpers: {},
6+
include: {},
7+
bootstrap: false,
8+
mocha: {},
9+
name: 'sandbox-no-helpers',
10+
};

test/runner/definitions_test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,22 @@ describe('Definitions', function () {
283283
done()
284284
})
285285
})
286+
287+
it('def should create definition file with empty Methods interface when no helpers configured', done => {
288+
exec(`${runner} def --config ${codecept_dir}/codecept.no-helpers.js`, (err, stdout) => {
289+
stdout.should.include('Definitions were generated in steps.d.ts')
290+
const types = typesFrom(`${codecept_dir}/steps.d.ts`)
291+
types.should.be.valid
292+
293+
const definitionFile = types.getSourceFileOrThrow(`${codecept_dir}/steps.d.ts`)
294+
const fileContent = definitionFile.getFullText()
295+
fileContent.should.include('interface Methods {}')
296+
fileContent.should.include('interface I extends WithTranslation<Methods>')
297+
298+
assert(!err)
299+
done()
300+
})
301+
})
286302
})
287303

288304
/**

0 commit comments

Comments
 (0)