打字稿4.6和箭头功能
我们最近更新到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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道我为解决这个问题做了什么,但是在线的某个地方,我改变了一些无关的东西,而这个“问题”消失了。
I do not know what i did to resolve this, but somewhere down the line i changed something unrelated and this 'issue' went away.