rothnic
rothnic
WWindmill
Created by rothnic on 5/20/2025 in #help
Using Types as Inputs to Script
One thing I've always found to be confusing is why we can't reuse a type for the input definition for a script. For example, to make the input inference work for this example, I'd need to copy and paste the RelativeDateConfig definition and replace the type reference with it for gt and lt. Maybe I'm just missing how you'd expect this to be handled.
export type RelativeDateConfig = {label: "today", hours?: number, days?: number} | {label: "now"} | {label: "custom", value: string};

export async function main(
filterObj: {},
dateFieldConfigs: {
field: string,
gt?: RelativeDateConfig,
lt?: RelativeDateConfig
}[]
) {
export type RelativeDateConfig = {label: "today", hours?: number, days?: number} | {label: "now"} | {label: "custom", value: string};

export async function main(
filterObj: {},
dateFieldConfigs: {
field: string,
gt?: RelativeDateConfig,
lt?: RelativeDateConfig
}[]
) {
In this example, the UI will render an input for a generic object, rather than the type definition that is inferred correctly if i were to duplicate the code and replace the reference. This feels bad from a DRY standpoint. While I'm here, I also wish that for these kinds of types we might want to reuse across the project, we could define just reusable types within windmill. This would be something different than defining a new Resource Type. I know we could import them from another script, but it feels like that is a lot less discoverable in the project UI.
4 replies