2018-09-22 12:34:26 +02:00
|
|
|
import { Type } from "./Type"
|
|
|
|
|
|
|
|
export class LiteralTypeType implements Type {
|
2019-03-26 06:34:40 +01:00
|
|
|
public kind = "LiteralType"
|
2018-09-22 12:34:26 +02:00
|
|
|
|
2019-05-31 13:25:51 +02:00
|
|
|
constructor(public value: string, public isDotDotDot = false, public isQuestion = false) {}
|
2018-09-22 12:34:26 +02:00
|
|
|
|
2019-03-26 06:34:40 +01:00
|
|
|
public toConstructor() {
|
2019-05-31 13:25:51 +02:00
|
|
|
return `new LiteralTypeType(${JSON.stringify(this.value)}, ${this.isDotDotDot}, ${this.isQuestion})`
|
2018-09-22 12:34:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-26 06:34:40 +01:00
|
|
|
public toString() {
|
2018-09-22 12:34:26 +02:00
|
|
|
return JSON.stringify(this.value)
|
|
|
|
}
|
|
|
|
|
2019-03-26 06:34:40 +01:00
|
|
|
public convert(argument) {
|
|
|
|
if (argument === this.value) {
|
|
|
|
return argument
|
|
|
|
}
|
2018-09-22 12:34:26 +02:00
|
|
|
throw new Error(
|
|
|
|
`Argument does not match expected value (${
|
|
|
|
this.value
|
|
|
|
}): ${argument}`,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|