打字稿4.6和箭头功能

发布于 2025-01-22 17:00:12 字数 823 浏览 0 评论 0原文

我们最近更新到Typescript 4.6(来自4.5),并遇到了一些奇怪的问题。

例如,我们以前在#handleunsaveddata = async(事件:toferunloadevent)上定义了一个函数:Promise< boolean> => {并将this.workSpaceService.HandLeunSaved = this

。 ; boolean> { and'通过箭头,而是this.workSpaceService.handleunsaved = event =>这个。#thangeunsaveddata(event);

看来,我们似乎无法在构造函数之前访问构造函数的服务? 之前:

export class HeaderComponent {
  @Input() close = this.workspaceService.close;

  constructor(private workspaceService: WorkspaceService) { }
}

之后:

export class HeaderComponent {

  constructor(private workspaceService: WorkspaceService) { }

  close() {
    this.workspaceService.close();
  }
}

我觉得我在这里错过了一些非常基本的东西,但是我已经阅读并重新阅读了TS 4.6文档,并努力寻找引起这一点的原因。

We recently updated to typescript 4.6 (from 4.5) and are experiencing some weird this issues.

for example we previously had a function defined at #handleUnsavedData = async (event: BeforeUnloadEvent): Promise<boolean> => { and passed to a service with this.workspaceService.handleUnsaved = this.#handleUnsavedData

it appears we now need to define it like async #handleUnsavedData(event: BeforeUnloadEvent): Promise<boolean> { and 'pass' it with the arrow instead this.workspaceService.handleUnsaved = event => this.#handleUnsavedData(event);

It also appears that we can no longer access constructor injected services before the constructor?
Before:

export class HeaderComponent {
  @Input() close = this.workspaceService.close;

  constructor(private workspaceService: WorkspaceService) { }
}

After:

export class HeaderComponent {

  constructor(private workspaceService: WorkspaceService) { }

  close() {
    this.workspaceService.close();
  }
}

I feel like I'm missing something incredibly basic here, but i have read and re-read the TS 4.6 documentation and am struggling to find what is causing this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾挽 2025-01-29 17:00:12

我不知道我为解决这个问题做了什么,但是在线的某个地方,我改变了一些无关的东西,而这个“问题”消失了。

I do not know what i did to resolve this, but somewhere down the line i changed something unrelated and this 'issue' went away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文