Lukas
Lukas

Reputation: 10360

TypeScript Type: String matching pattern

I am querying a system API (Linux' DBus API) that expects 3 strings:

So I could write the signature of the TypeScript methods that calls the interface like so:

getInterface(service: string, path: string, name: string): DBusInterface;

But I know , service, path and name each follow specific string patterns:

(Regex not 100% correct, but here for comprehensibility)

I am wondering if it is possible to type guard the 3 parameters to match these patterns, like

type ServiceName: /^org\.bluez/

Upvotes: 0

Views: 656

Answers (1)

Asaf Aviv
Asaf Aviv

Reputation: 11770

Currently as of 11/2019 this is not possible, there is an open suggestion for this for a while now that you can keep track of here https://github.com/Microsoft/TypeScript/issues/6579

You can read the comments and maybe find something useful

Upvotes: 1

Related Questions