diff --git a/v2/internal/typescriptify/typescriptify.go b/v2/internal/typescriptify/typescriptify.go index 82a74437b..3d7256038 100644 --- a/v2/internal/typescriptify/typescriptify.go +++ b/v2/internal/typescriptify/typescriptify.go @@ -3,7 +3,7 @@ package typescriptify import ( "bufio" "fmt" - "io/ioutil" + "io" "log" "os" "path" @@ -394,7 +394,7 @@ func loadCustomCode(fileName string) (map[string]string, error) { } defer f.Close() - bytes, err := ioutil.ReadAll(f) + bytes, err := io.ReadAll(f) if err != nil { return result, err } @@ -430,7 +430,7 @@ func (t TypeScriptify) backup(fileName string) error { } defer fileIn.Close() - bytes, err := ioutil.ReadAll(fileIn) + bytes, err := io.ReadAll(fileIn) if err != nil { return err } @@ -440,7 +440,7 @@ func (t TypeScriptify) backup(fileName string) error { backupFn = path.Join(t.BackupDir, backupFn) } - return ioutil.WriteFile(backupFn, bytes, os.FileMode(0o700)) + return os.WriteFile(backupFn, bytes, os.FileMode(0o700)) } func (t TypeScriptify) ConvertToFile(fileName string, packageName string) error { @@ -894,7 +894,7 @@ func (t *typeScriptClassBuilder) addField(fld, fldType string, isAnyType bool) { isOptional := strings.HasSuffix(fld, "?") strippedFieldName := strings.ReplaceAll(fld, "?", "") if !regexp.MustCompile(jsVariableNameRegex).Match([]byte(strippedFieldName)) { - fld = fmt.Sprintf(`"%s"`, fld) + fld = fmt.Sprintf(`"%s"`, strippedFieldName) if isOptional { fld += "?" } diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index f33f68777..e1ca9279f 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated several broken links in the "How Does It Work?" page on the website. Changed by [@oguz-yilmaz](https://github.com/oguz-yilmaz) in [PR #3469](https://github.com/wailsapp/wails/pull/3469) - Upgraded Go version in CI to 1.22 by [@leaanthony](https://github.com/leaanthony) in [#3473](https://github.com/wailsapp/wails/pull/3473). +### Fixed +- Fixed optional type generation where an extra `?` would be placed inside the field name instead of outside the name `"field?"?` vs `"field"?`. Fixed by [@atterpac](https://github.com/atterpac) in [#3476](https://github.com/wailsapp/wails/pull/3476) + ## v2.8.2 - 2024-05-08 ### Breaking Change