-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #1457
- Loading branch information
Showing
9 changed files
with
311 additions
and
55 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
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,59 @@ | ||
import { Type } from "./abstract"; | ||
|
||
/** | ||
* Represents a rest type | ||
* ```ts | ||
* type Z = [1, ...2[]] | ||
* // ^^^^^^ | ||
* ``` | ||
*/ | ||
export class RestType extends Type { | ||
/** | ||
* The type of the rest array elements. | ||
*/ | ||
elementType: Type; | ||
|
||
/** | ||
* The type name identifier. | ||
*/ | ||
readonly type = "rest"; | ||
|
||
/** | ||
* Create a new RestType instance. | ||
* | ||
* @param elementType The type of the array's elements. | ||
*/ | ||
constructor(elementType: Type) { | ||
super(); | ||
this.elementType = elementType; | ||
} | ||
|
||
/** | ||
* Clone this type. | ||
* | ||
* @return A clone of this type. | ||
*/ | ||
clone(): Type { | ||
return new RestType(this.elementType.clone()); | ||
} | ||
|
||
/** | ||
* Test whether this type equals the given type. | ||
* | ||
* @param type The type that should be checked for equality. | ||
* @returns TRUE if the given type equals this type, FALSE otherwise. | ||
*/ | ||
equals(type: Type): boolean { | ||
if (!(type instanceof RestType)) { | ||
return false; | ||
} | ||
return type.elementType.equals(this.elementType); | ||
} | ||
|
||
/** | ||
* Return a string representation of this type. | ||
*/ | ||
toString() { | ||
return `...${this.elementType.toString()}`; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { RestType } from "../../../models"; | ||
|
||
import { TypeSerializerComponent } from "../../components"; | ||
import { RestType as JSONRestType } from "../../schema"; | ||
|
||
export class RestTypeSerializer extends TypeSerializerComponent<RestType> { | ||
supports(t: unknown) { | ||
return t instanceof RestType; | ||
} | ||
|
||
/** | ||
* Will be run after [[TypeSerializer]] so `type` will already be set. | ||
* @param type | ||
* @param obj | ||
*/ | ||
toObject(type: RestType, obj: Pick<JSONRestType, "type">): JSONRestType { | ||
return { | ||
...obj, | ||
elementType: this.owner.toObject(type.elementType), | ||
}; | ||
} | ||
} |
Oops, something went wrong.