Skip to content

Conversation

@l2ysho
Copy link
Contributor

@l2ysho l2ysho commented Jan 19, 2026

Draft summary

  • output: path to a directory where the files generated should be outputted, default ./.generated/actor/ (actual path in code is gonna be resolve(cwd(), output), followed by mkdir(), then storing in there). char: o

  • strict: whether generated interfaces should have an index definition ([key: string]: unknown if this is set to false), default true. char: s

  • [can optionally be done] language: the language to generate the types for (currently only TypeScript, but ideally structure the code in a way where we can easily add in new languages). char: l

  • [optional, nice to have, can be for future work] [input/output/dataset/key-value-store]-schema: path to a specific schema to generate types for

  • [don't implement this until we discuss it] add-to-ignore: whether the cli should add the generated files to files like .prettierignore or the biome config, default: false.

  • tests

@l2ysho l2ysho linked an issue Jan 19, 2026 that may be closed by this pull request
@github-actions github-actions bot added this to the 132nd sprint - Tooling team milestone Jan 19, 2026
@github-actions github-actions bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Jan 19, 2026
@l2ysho l2ysho force-pushed the 993-implement-a-command-for-generating-type-definitions-from-schemas branch from bbaf98e to dcc207c Compare January 21, 2026 13:18
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Jan 21, 2026
Comment on lines +63 to +67
const { inputSchema, inputSchemaPath } = await readAndValidateInputSchema({
forcePath: this.args.path,
cwd: process.cwd(),
action: 'Generating types from',
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate-type share a validation logic with validate-schema now

char: 'o',
description: 'Directory where the generated files should be outputted.',
required: false,
default: './.generated/actor/',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actor templates have typescript setup with only src as include, so you cannot import it right away and you have to adjust it. Maybe better idea is to generate it directly to src/.generated/actor/ ? cc @vladfrangu

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be best to discuss with @B4nan and @patrikbraborec too. Or maybe we wanna make it like how prisma handles it? so you'd have @apify/actor in node-modules which gets filled out by the cli?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you'd have @apify/actor in node-modules which gets filled out by the cli?

I think changed this in v7, because it produced a lot of side effects, e.g. with caching. But we could explore this as well, maybe for our use case it would be fine.

If we won't go that way, I am slightly in favor of putting this into the src folder, the alternative would be dynamically appending the .generated folder to includes in tsconfig. But that would mean you end up with dist/src and dist/.generated if I'm not mistaken, which is a bit ugly (but also rather irrelevant).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw modifying tsconfig can be risky, people may have god knows what setups in their tsconfig files and we shouldn't randomly append our folder.

I think changed this in v7, because it produced a lot of side effects, e.g. with caching. But we could explore this as well, maybe for our use case it would be fine.

Can you help me understand what you mean by this? Did prisma change this or what are you referring to with v7?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just came back cuz I read that, holy heck I did not know.... But they also use the top level generated dir by def, interesting

Comment on lines +1 to +2
import { readFile } from 'node:fs/promises';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really just starting point of tests. No complex scenarios.

});

expect(lastErrorMessage()).toMatch(/Generated types written to/);
expect(lastErrorMessage()).toMatch(/\.generated\/actor\/complex\.ts/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use path.join and i think you can do .toInclude or just expect(lastErrorMessage().includes()).toBeTruthy()

const { lastErrorMessage } = useConsoleSpy();

describe('apify actor generate-types', () => {
const { joinPath, beforeAllCalls, afterAllCalls } = useTempPath('generate-types', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually this hook is called from the top level, followed by importing the commands with await import, but if it WORKS even like this... fun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement a command for generating type definitions from schemas

4 participants