VSCode 源代码中的这一行是什么意思?



我在VS code源代码中找到了以下代码。https://github.com/microsoft/vscode/blob/5da4d93f579f3fadbaf835d79dc47d54c0d6b6b4/src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts L166

看起来ICommentService是一个接口。我认为界面不能是一个装饰者。https://www.typescriptlang.org/docs/handbook/decorators.html parameter-decorators

@ICommentService是什么?

ICommentService实际上是一个decorator函数:

export const ICommentService = createDecorator<ICommentService>('commentService');

和一个接口(就像上面链接的那样):

export interface ICommentService {
...
}

可以是这两种情况,因为TypeScript中的标识符既可以引用值(在运行时使用)也可以引用类型(在类型检查时使用)。

最新更新