diff --git a/v3/internal/generator/render/info.go b/v3/internal/generator/render/info.go index b3305e3f8..3947f117a 100644 --- a/v3/internal/generator/render/info.go +++ b/v3/internal/generator/render/info.go @@ -50,11 +50,14 @@ func modelinfo(model *collect.ModelInfo, useInterfaces bool) (info modelInfo) { createList.WriteRune('(') for i, param := range model.TypeParams { + param = typeparam(i, param) + if i > 0 { params.WriteRune(',') paramList.WriteString(", ") createList.WriteString(", ") } + params.WriteString(param) paramList.WriteString(param) diff --git a/v3/internal/generator/render/templates/models.js.tmpl b/v3/internal/generator/render/templates/models.js.tmpl index 5fe0db83c..6c0e98b8b 100644 --- a/v3/internal/generator/render/templates/models.js.tmpl +++ b/v3/internal/generator/render/templates/models.js.tmpl @@ -147,7 +147,10 @@ export class {{jsid $model.Name}} { * Given creation functions for each type parameter, * returns a creation function for a concrete instance * of the generic class {{jsid $model.Name}}. - * @template {{$template.Params}} + {{- range $i, $param := $model.TypeParams}} + {{- $param = (typeparam $i $param)}} + * @template [{{$param}}=any] + {{- end}} {{- range $i, $param := $model.TypeParams}} {{- $param = (typeparam $i $param)}} * @param {(source: any) => {{$param -}} } $$createParam{{$param}} diff --git a/v3/internal/generator/render/templates/models.ts.tmpl b/v3/internal/generator/render/templates/models.ts.tmpl index d5ec2a971..a6073af08 100644 --- a/v3/internal/generator/render/templates/models.ts.tmpl +++ b/v3/internal/generator/render/templates/models.ts.tmpl @@ -139,7 +139,12 @@ export {{if $info.IsInterface}}interface{{else}}class{{end}} {{jsid $model.Name} * Creates a new {{jsid $model.Name}} instance from a string or object. {{- end}} */ - static createFrom{{$template.ParamList}}({{if $template.ParamList}} + static createFrom{{if $template.ParamList}}< + {{- range $i, $param := $model.TypeParams}} + {{- $param = (typeparam $i $param)}} + {{- if gt $i 0}}, {{end -}} + {{$param}} = any + {{- end}}>{{end}}({{if $template.ParamList}} {{- range $i, $param := $model.TypeParams}} {{- $param = (typeparam $i $param)}} {{- if gt $i 0}}, {{end -}} diff --git a/v3/internal/runtime/desktop/@wailsio/runtime/src/create.ts b/v3/internal/runtime/desktop/@wailsio/runtime/src/create.ts index dc3db4aad..72965eaa6 100644 --- a/v3/internal/runtime/desktop/@wailsio/runtime/src/create.ts +++ b/v3/internal/runtime/desktop/@wailsio/runtime/src/create.ts @@ -11,7 +11,7 @@ The electron alternative for Go /** * Any is a dummy creation function for simple or unknown types. */ -export function Any(source: any): T { +export function Any(source: any): T { return source; } @@ -28,7 +28,7 @@ export function ByteSlice(source: any): string { * and returns an in-place creation function for an array * whose elements are of that type. */ -export function Array(element: (source: any) => T): (source: any) => T[] { +export function Array(element: (source: any) => T): (source: any) => T[] { if (element === Any) { return (source) => (source === null ? [] : source); } @@ -49,7 +49,7 @@ export function Array(element: (source: any) => T): (source: any) => T[] { * and returns an in-place creation function for an object * whose keys and values are of those types. */ -export function Map(key: (source: any) => string, value: (source: any) => V): (source: any) => Record { +export function Map(key: (source: any) => string, value: (source: any) => V): (source: any) => Record { if (value === Any) { return (source) => (source === null ? {} : source); } @@ -69,7 +69,7 @@ export function Map(key: (source: any) => string, value: (source: any) => V): * Nullable takes a creation function for an arbitrary type * and returns a creation function for a nullable value of that type. */ -export function Nullable(element: (source: any) => T): (source: any) => (T | null) { +export function Nullable(element: (source: any) => T): (source: any) => (T | null) { if (element === Any) { return Any; } @@ -81,10 +81,9 @@ export function Nullable(element: (source: any) => T): (source: any) => (T | * Struct takes an object mapping field names to creation functions * and returns an in-place creation function for a struct. */ -export function Struct< - T extends { [_: string]: ((source: any) => any) }, - U extends { [Key in keyof T]?: ReturnType } ->(createField: T): (source: any) => U { +export function Struct(createField: Record any>): + = any>(source: any) => U +{ let allAny = true; for (const name in createField) { if (createField[name] !== Any) {