简体   繁体   English

通过文件扩展摩纳哥编辑提示

[英]Extend monaco editor hints by file

I'm looking for a way to extend the type hints in monaco editor (like Object, String or Boolean) with my own king of type. 我正在寻找一种方法来扩展摩纳哥编辑器中的类型提示(如Object,String或Boolean),并使用我自己的类型之王。 The goal is that the editor knows the type and can provide code completion to the specific type. 目的是使编辑器知道类型,并可以为特定类型提供代码完成。

All the previous examples I found are by inserting strings on addExtraLib but this is not professional: 我发现的所有先前示例都是通过在addExtraLib上插入字符串来addExtraLib但这并不专业:

monaco.languages.typescript.javascriptDefaults.addExtraLib([
    'declare class MyClass {',
    '    count: number',
    '}'
].join('\n'));

What I am looking for is to provide eg following .d.ts file or any file to let the editor know of my type, to better automate the process: 我正在寻找的是提供例如.d.ts文件或任何以下文件,以使编辑器知道我的类型,以更好地实现该过程的自动化:

  // myclass.d.ts
  export class MyClass = {
    count: number
  }

Is there something I am missing out? 有什么我想念的吗?

After a long time I have finally come across an issue where is explained how to import type definitions by file. 经过很长一段时间,我终于遇到了一个问题,其中解释了如何通过文件导入类型定义。

But as also stated in the comment, it still has to be string. 但是,正如评论中所述,它仍然必须是字符串。 The end solution I came up with is to raw-import my files where the types are defined in strings and then add it that way into monaco editor. 我想出的最终解决方案是将导入的文件以字符串形式定义的类型原始导入,然后以这种方式将其添加到monaco编辑器中。

Linkt to comment 链接评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM