2018-09-22 12:34:26 +02:00
|
|
|
import { Type } from "./Type"
|
|
|
|
|
|
|
|
export class StringType implements Type {
|
2019-03-26 06:34:40 +01:00
|
|
|
public static instance = new StringType()
|
|
|
|
public kind = "string"
|
2018-09-22 12:34:26 +02:00
|
|
|
|
2019-03-26 06:34:40 +01:00
|
|
|
public toConstructor() {
|
2018-11-21 06:56:01 +01:00
|
|
|
return "StringType.instance"
|
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 this.kind
|
|
|
|
}
|
|
|
|
|
2019-03-26 06:34:40 +01:00
|
|
|
public convert(argument) {
|
|
|
|
if (typeof argument === "string") {
|
|
|
|
return argument
|
|
|
|
}
|
2018-09-22 12:34:26 +02:00
|
|
|
throw new Error(`Can't convert to string: ${argument}`)
|
|
|
|
}
|
|
|
|
}
|