Skip to content

Commit

Permalink
Improve typing of RunResult (#165)
Browse files Browse the repository at this point in the history
Improve typing of RunResult:
 - Add default for generator type in RunResult
 - Improve typing in helpers to make typescript better at infering
generator type
  • Loading branch information
jvasseur committed Jan 24, 2023
1 parent 028e982 commit e12bf11
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export type Dependency = string | Parameters<Environment['registerStub']> | Para

type GeneratorNew<GenParameter extends YeomanGenerator = YeomanGenerator> = new (
...args: ConstructorParameters<typeof YeomanGenerator<GenParameter['options']>>
) => YeomanGenerator<GenParameter['options']>;
) => GenParameter;
type GeneratorBuilder<GenParameter extends YeomanGenerator = YeomanGenerator> = (
...args: ConstructorParameters<typeof YeomanGenerator<GenParameter['options']>>
) => YeomanGenerator<GenParameter['options']>;
) => GenParameter;

export type GeneratorConstructor<GenParameter extends YeomanGenerator = YeomanGenerator> =
| GeneratorNew<GenParameter>
Expand Down Expand Up @@ -305,7 +305,7 @@ export class YeomanTest {
*/

run<GeneratorType extends YeomanGenerator = YeomanGenerator>(
GeneratorOrNamespace: string | GeneratorConstructor,
GeneratorOrNamespace: string | GeneratorConstructor<GeneratorType>,
settings?: RunContextSettings,
envOptions?: Options,
): RunContext<GeneratorType> {
Expand All @@ -332,7 +332,7 @@ export class YeomanTest {
*/

create<GeneratorType extends YeomanGenerator = YeomanGenerator>(
GeneratorOrNamespace: string | GeneratorConstructor,
GeneratorOrNamespace: string | GeneratorConstructor<GeneratorType>,
settings?: RunContextSettings,
envOptions?: Options,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/run-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends
private readonly onEnvironmentCallbacks: Array<(this: this, env: Environment) => any> = [];

private readonly inDirCallbacks: any[] = [];
private readonly Generator: string | GeneratorConstructor | typeof Generator;
private readonly Generator: string | GeneratorConstructor<GeneratorType> | typeof Generator;
private readonly helpers: YeomanTest;
private readonly temporaryDir = path.join(tempDirectory, crypto.randomBytes(20).toString('hex'));

Expand All @@ -94,7 +94,7 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends
*/

constructor(
generatorType: string | GeneratorConstructor | typeof Generator,
generatorType: string | GeneratorConstructor<GeneratorType> | typeof Generator,
settings?: RunContextSettings,
envOptions: Options = {},
helpers = defaultHelpers,
Expand Down
2 changes: 1 addition & 1 deletion src/run-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type RunResultOptions<GeneratorType extends Generator> = {
* This class provides utilities for testing generated content.
*/

export default class RunResult<GeneratorType extends Generator> {
export default class RunResult<GeneratorType extends Generator = Generator> {
env: any;
generator: GeneratorType;
cwd: string;
Expand Down

0 comments on commit e12bf11

Please sign in to comment.