Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for simple Identifier replacement in type_mappings config #74

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

KONFeature
Copy link

@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