Skip to content

Commit

Permalink
feat(jsii): support aliasing type unions
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller committed Jul 21, 2020
1 parent 6f2a181 commit 38ebb91
Show file tree
Hide file tree
Showing 11 changed files with 518 additions and 26 deletions.
23 changes: 22 additions & 1 deletion packages/@jsii/spec/lib/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ export interface NamedTypeReference {
*/
fqn: FQN;
}

export function isNamedTypeReference(
ref: TypeReference | undefined,
): ref is NamedTypeReference {
Expand Down Expand Up @@ -746,7 +747,8 @@ export function isMethod(callable: Callable): callable is Method {
/**
* Represents a type definition (not a type reference).
*/
export type Type = TypeBase & (ClassType | EnumType | InterfaceType);
export type Type = TypeBase &
(ClassType | EnumType | InterfaceType | NamedUnionType);

/**
* Common attributes of a type definition.
Expand Down Expand Up @@ -795,6 +797,7 @@ export enum TypeKind {
Class = 'class',
Enum = 'enum',
Interface = 'interface',
NamedUnion = 'union',
}

/**
Expand Down Expand Up @@ -918,6 +921,24 @@ export function isEnumType(type: Type | undefined): type is EnumType {
return type?.kind === TypeKind.Enum;
}

/**
* Represents a named type union.
*/
export interface NamedUnionType extends TypeBase {
kind: TypeKind.NamedUnion;

/**
* Candidate types for the union.
*/
types: TypeReference[];
}

export function isNamedUnionType(
type: Type | undefined,
): type is NamedUnionType {
return type?.kind === TypeKind.NamedUnion;
}

/**
* Return whether this type is a class or interface type
*/
Expand Down
10 changes: 9 additions & 1 deletion packages/@scope/jsii-calc-lib/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@
"stability": "deprecated",
"summary": "Creates a Number object."
},
"locationInModule": {
"filename": "lib/index.ts",
"line": 35
},
"parameters": [
{
"docs": {
Expand Down Expand Up @@ -626,6 +630,10 @@
"initializer": {
"docs": {
"stability": "deprecated"
},
"locationInModule": {
"filename": "lib/submodule/index.ts",
"line": 11
}
},
"kind": "class",
Expand Down Expand Up @@ -668,5 +676,5 @@
}
},
"version": "0.0.0",
"fingerprint": "w6/8Kda6/JitSbpMK3LGPK5JGRxJ50gflR5S4sUEHKk="
"fingerprint": "fVfpIK7xUajlT1zkHIJ8uYJPvy0gLgEe5BM8afu1mVg="
}
2 changes: 1 addition & 1 deletion packages/jsii-calc/lib/compliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ export class NodeStandardLibrary {
/**
* Returns the current os.platform() from the "os" node module.
*/
public get osPlatform() {
public get osPlatform(): string {
return os.platform();
}

Expand Down
Loading

0 comments on commit 38ebb91

Please sign in to comment.