Skip to content

Commit

Permalink
Add ref comment for typealias (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongwartz authored Mar 17, 2024
1 parent bd1df67 commit bda315f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions codegen/snippet-tests/output/06_with_type_alias.pkl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export interface MyClassToBeAliased {
b: number
}

// Ref: Pkl type `06-withTypeAlias.MyStringAlias`.
type MyStringAlias = string

// Ref: Pkl type `06-withTypeAlias.MyAliasedClass`.
type MyAliasedClass = MyClassToBeAliased

// LoadFromPath loads the pkl module at the given path and evaluates it into a N06WithTypeAlias
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface MyCustomClassName {
name: string
}

// Ref: Pkl type `n12.pkl.typescript.tests.moduleNameOverride.AliasName`.
type ThisTypeAlias = "x" | "y" | MyCustomClassName

// LoadFromPath loads the pkl module at the given path and evaluates it into a N12TypescriptGeneratedInterface
Expand Down
6 changes: 5 additions & 1 deletion codegen/src/internal/TypeAliasGen.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ typealiaz: reflect.TypeAlias = mapping.source as reflect.TypeAlias

type: Type = typegen.generateType(typealiaz.referent, typealiaz, mappings)

contents = "type \(mapping.name) = \(type.render(typescriptModule))"
contents = new Listing {
"// Ref: Pkl type `\(typealiaz.enclosingDeclaration.name).\(typealiaz.name)`."

"type \(module.mapping.name) = \(type.render(module.typescriptModule))"
}.join("\n")

0 comments on commit bda315f

Please sign in to comment.