Is it possible to specify string format with TypeScript?

Viewed 5242

I just wonder - is it a way to check if the string matches some pattern via TypeScript.

I don't want to do the checks in the runtime.

//What I have now
public id: string; //can be whatever string 

//What I want to see
public id: IdType; //Some type?
id = '0000-0000-0000-0001'//valid
id = 'whatever'//invalid

So is it a way to define string format?

1 Answers
Related