Closed DetachHead closed 3 years ago
i'm giving this a shot https://github.com/DetachHead/typescript-is
some things to consider:
${string}
, ${number}
, etc. are implemented in such a way that leads to some unexpected behavior.
is<`foo${string}${number}bar`>
would compile to something like
function _3660(object) {
;
if (object.match(/foo.*\dbar/))
return {
message: "validation failed at " + path.join(".") + ": expected template literal 'foo${string}${number}bar'",
path: path.slice(),
reason: {type: "string-literal", value: "foo${string}${number}bar"}
};
else
return null;
}
though this would mean the type checker behaves differently to the typescript compiler, which i imagine is not desired. in that case the generated regex could look like /foo.\dbar/
@woutervh- any advice?
i went with treating the values the same way the compiler does
Thanks again.
Released v0.18.0
https://github.com/woutervh-/typescript-is/releases/tag/v0.18.0
https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html