-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suport for typealias types (and never type) (#13)
* Add suport for typealias types (and never type) * add nothing type to primitive snippet test
- Loading branch information
1 parent
b569d0b
commit 20ea5f1
Showing
11 changed files
with
125 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ float: Float | |
bool: Boolean | ||
nullType: Null | ||
anyType: Any | ||
|
||
nothingType: nothing |
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,12 @@ | ||
typealias MyStringAlias = String | ||
|
||
x: MyStringAlias | ||
|
||
class MyClassToBeAliased { | ||
a: String | ||
b: Int | ||
} | ||
|
||
typealias MyAliasedClass = MyClassToBeAliased | ||
|
||
y: MyAliasedClass |
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,35 @@ | ||
// This file was generated by `pkl-typescript` from Pkl module `06-withTypeAlias`. | ||
// DO NOT EDIT. | ||
import * as pklTypescript from "@pkl-community/pkl-typescript" | ||
|
||
// Ref: Module root. | ||
export interface N06WithTypeAlias { | ||
x: MyStringAlias | ||
|
||
y: MyAliasedClass | ||
} | ||
|
||
// Ref: Pkl class `06-withTypeAlias.MyClassToBeAliased`. | ||
export interface MyClassToBeAliased { | ||
a: string | ||
|
||
b: number | ||
} | ||
|
||
type MyStringAlias = string | ||
|
||
type MyAliasedClass = MyClassToBeAliased | ||
|
||
// LoadFromPath loads the pkl module at the given path and evaluates it into a N06WithTypeAlias | ||
export const loadFromPath = async (path: string): Promise<N06WithTypeAlias> => { | ||
const evaluator = await pklTypescript.newEvaluator(pklTypescript.PreconfiguredOptions); | ||
try { | ||
const result = await load(evaluator, pklTypescript.FileSource(path)); | ||
return result | ||
} finally { | ||
evaluator.close() | ||
} | ||
}; | ||
|
||
export const load = (evaluator: pklTypescript.Evaluator, source: pklTypescript.ModuleSource): Promise<N06WithTypeAlias> => | ||
evaluator.evaluateModule(source) as Promise<N06WithTypeAlias>; |
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 |
---|---|---|
|
@@ -10,3 +10,5 @@ mappings: List<TypescriptMapping> | |
|
||
/// The TypeScript contents | ||
contents: String | ||
|
||
typescriptModule: 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,13 @@ | ||
module pkl.typescript.internal.TypeAliasGen | ||
|
||
extends "Gen.pkl" | ||
|
||
import "typegen.pkl" | ||
import "Type.pkl" | ||
import "pkl:reflect" | ||
|
||
typealiaz: reflect.TypeAlias = mapping.source as reflect.TypeAlias | ||
|
||
type: Type = typegen.generateType(typealiaz.referent, typealiaz, mappings) | ||
|
||
contents = "type \(mapping.name) = \(type.render(typescriptModule))" |
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
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