Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 类型脚本类型:字符串匹配模式_Typescript - Fatal编程技术网

Typescript 类型脚本类型:字符串匹配模式

Typescript 类型脚本类型:字符串匹配模式,typescript,Typescript,我正在查询一个系统API(Linux'DBusAPI),它需要3个strings: 服务 路径 name 因此,我可以编写调用接口的TypeScript方法的签名,如下所示: getInterface(service: string, path: string, name: string): DBusInterface; 但我知道,服务、路径和名称都遵循特定的字符串模式: 服务=/^org\.bluez/ 路径=/(\/[a-zA-Z]*)+/ name=/([a-zA-Z]+\)+/

我正在查询一个系统API(Linux'
DBus
API),它需要3个
string
s:

  • 服务
  • 路径
  • name
因此,我可以编写调用接口的TypeScript方法的签名,如下所示:

getInterface(service: string, path: string, name: string): DBusInterface;
但我知道,
服务
路径
名称
都遵循特定的字符串模式:

  • 服务
    =
    /^org\.bluez/
  • 路径=
    /(\/[a-zA-Z]*)+/
  • name
    =
    /([a-zA-Z]+\)+/
(正则表达式不是100%正确,但此处是为了便于理解)

我想知道是否可以键入3个参数来匹配这些模式,如

type ServiceName: /^org\.bluez/

目前截至2019年11月,这是不可能的,现在有一个公开的建议,您可以在这里跟踪


您可以阅读评论,也许会发现一些有用的东西

谢谢您!你能把这个作为一个答案,然后我可以接受这个解决了!