0

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

  • service
  • path
  • name

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:

  • service = /^org\.bluez/
  • path = /(\/[a-zA-Z]*)+/
  • name = /([a-zA-Z]+\.)+/

(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/
1
  • Thank you Asaf! Can you post this as an answer, then I can accept this as solved! <3 Commented Nov 5, 2019 at 8:41

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.