Skip to content

Add support for simple Identifier replacement in type_mappings config #74

Open
KONFeature wants to merge 2 commits intogzuidhof:mainfrom
KONFeature:feat/type-alias-mapping
Open

Add support for simple Identifier replacement in type_mappings config #74
KONFeature wants to merge 2 commits intogzuidhof:mainfrom
KONFeature:feat/type-alias-mapping

Conversation

@KONFeature
Copy link
Copy Markdown

@KONFeature KONFeature commented Nov 28, 2024

Support the replacement of simple ast.Ident via type mappings, thus providing support for type alias replacement on the config level.

Replacement similar to the previous ast.SelectorExpr, just the longtype is built with id_{identifierName}.

Could be very useful in projects with a lot of type aliases, for now stuck with adding a lot of tstypes tags

Example

Go:

type DurationString = string

type CacheConfig struct {
	Key string        `json:"key"`
	Ttl DurationString `json:"ttl"`
}

Config:

packages:
- path: "..."
    type_mappings:
      id_DurationString: "TsDurationString"
    frontmatter:
      export type TsDurationString = `${number}ms` | `${number}s` | `${number}m` | `${number}h`;

Output:

// Code generated by tygo. DO NOT EDIT.
export type TsDurationString = `${number}ms` | `${number}s` | `${number}m` | `${number}h`;
//////////
// source: alias.go

/**
 * Represent a duration that would be parsed with smth like `time.ParseDuration(...)`
 */
export type DurationString = string;
export interface CacheConfig {
  key: string;
  ttl: TsDurationString;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant