-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from mtt0/main
feat: support embed struct fields without `tstype: ",extends"`
- Loading branch information
Showing
8 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package embed | ||
|
||
import bookapp "github.com/gzuidhof/tygo/examples/bookstore" | ||
|
||
// TokenType Built-in type alias | ||
type TokenType string | ||
|
||
type StructEmbed struct { | ||
Base `json:",inline" tstype:",extends"` // embed struct with `tstype:"extends"` | ||
TokenType `json:"tokenType"` // built-in type field without `tstype:"extends"` | ||
Reference `json:"reference"` // embed struct without `tstype:"extends"` | ||
OtherReference Reference `json:"other_reference"` | ||
Bar string `json:"bar"` | ||
bookapp.Book `json:"book"` // embed external struct without `tstype:"extends"` | ||
*bookapp.Chapter `json:"chapter"` // embed external struct pointer without `tstype:"extends"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Code generated by tygo. DO NOT EDIT. | ||
import * as bookapp from "../bookstore" | ||
|
||
////////// | ||
// source: embed.go | ||
|
||
/** | ||
* TokenType Built-in type alias | ||
*/ | ||
export type TokenType = string; | ||
export interface StructEmbed extends Base { | ||
tokenType: TokenType; // built-in type field without `tstype:"extends"` | ||
reference: Reference; // embed struct without `tstype:"extends"` | ||
other_reference: Reference; | ||
bar: string; | ||
book: bookapp.Book; // embed external struct without `tstype:"extends"` | ||
chapter?: bookapp.Chapter; // embed external struct pointer without `tstype:"extends"` | ||
} | ||
|
||
////////// | ||
// source: types.go | ||
/* | ||
Package embed types defined in the Go file after the parsed file in the same package | ||
*/ | ||
|
||
export interface Base { | ||
id: string; | ||
} | ||
/** | ||
* Reference struct type, defined after embed.go, the same pkg but not the same file | ||
*/ | ||
export interface Reference { | ||
foo: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Package embed types defined in the Go file after the parsed file in the same package | ||
package embed | ||
|
||
type Base struct { | ||
ID string `json:"id"` | ||
} | ||
|
||
// Reference struct type, defined after embed.go, the same pkg but not the same file | ||
type Reference struct { | ||
Foo string `json:"foo"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters