WindmillWWindmill
Powered by
rothnicR
Windmill•9mo ago•
3 replies
rothnic

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.
WindmillJoin
3,362Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Recent Announcements
henri-c

Weekly kenote to tell you about our latest updates https://discord.com/channels/930051556043276338/1278977038430240813 https://youtube.com/live/2dGd9TdT8xs?feature=share

henri-c · 4d ago

Pyra

### HTTP tracing (EE) Capture HTTP requests made by job scripts as observability spans Features: - View HTTP request traces (method, URL, status, timing) in the job details UI - Auto-instrumentation for Native TypeScript, MITM proxy for other languages - Integrates with external OpenTelemetry collectors changelog: https://www.windmill.dev/changelog/http-tracing docs: https://www.windmill.dev/docs/advanced/instance_settings#http-tracing Additionally jobs memory metrics are now fully OSS!

Pyra · 2w ago

henri-c

First keynote of the year here https://discord.com/channels/930051556043276338/1278977038430240813 🙂

henri-c · 4w ago

Similar Threads

Using outputs from scripts as inputs
AnyaAAnya / help
12mo ago
Getting "connection refused" when accessing variables as script inputs
taydenTtayden / help
14mo ago
Python script custom return types
ggpeppGggpepp / help
5mo ago
Python script parameter types confusion
NackiNNacki / help
3y ago