小编Two*_*ois的帖子

typescript 使用导入的类扩展类

如果我扩展本地导出的类,它就可以工作。

工作示例:

export class classA {

    constructor() {
        super();
    }
}

export class classB extends classA {

constructor() {
    super();

    this.do();
}

private do(): void {
    // do something
}
Run Code Online (Sandbox Code Playgroud)

但是当我从文件外部导入 classA 时,它不起作用。

不工作的例子:

import { classA } from '../'; // I use index.ts file, so the reference is good.

export class classB extends classA {
    constructor() {
        super();

        this.do();
    }

    private do(): void {
        // do something
    }
}
Run Code Online (Sandbox Code Playgroud)

文件结构:

Root/
- index.ts

- classA(folder)/
   - index.ts
   - classA.ts …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript

5
推荐指数
1
解决办法
4901
查看次数

我可以在一个窗口中拥有多个 Powershell 控制台吗?

所以,现在我有很多打开的应用程序,通常是 3-4 个 powershell 控制台。我可以命令 powershell 窗口一起观看它们(左上角、右上角、左下角、右下角)。

所以这意味着如果我切换到另一个应用程序,当我切换回来时,我必须恢复所有多个 powershell 窗口才能再次看到它们。

我想要的是,为许多 powershell 创建一个“共享窗口”,因为当我需要一个时,我需要所有的人都能看到。

有没有办法做到这一点?

windows powershell

5
推荐指数
2
解决办法
6929
查看次数

如何在navigationEnd事件中获取当前路线配置?

如何获取当前路由器出口组件的静态路由路径,路由器事件中的角度激活了什么?

我在app.component 中需要它,因为如果我必须在所有组件中使用activatedRoute.snapshot 进行操作,那将是多余的

self.router.events.subscribe(event => {
    if (event instanceof NavigationEnd) {
        //I need here the path of route E.G '/page/:id/' from root

    }
});
Run Code Online (Sandbox Code Playgroud)

更新:在路由中:

export const MAIN_ROUTES: Routes = [
    { path: '', component: HomePage },
    { path: 'something', component: SomethingComponent },
    { path: 'page/:id', component: PageComponent }, //if the url is 'example.com/page/someId' than, I want to get the "path" field of this object and if I change the page, I need that inside the router event above. …
Run Code Online (Sandbox Code Playgroud)

angular

5
推荐指数
1
解决办法
6634
查看次数

如何在打字稿中安全地声明嵌套对象类型

我想创建一个包含组的对象,并且组有文件。可选择的文件有一个界面,如果一个组不包含其文件,我想得到错误。

export interface Group_A_Files {
    'movie': string
    'image': string
    'other': string
}

export interface Group_B_Files {
    'image': string
}

export const groups = {
    'groupA'  : {
        'someField': 'some value',
        'files': <Group_A_Files> {
            'movie': '',
            'image': '',
        } // I want to get an error from the IDE, because other is required in Group_A_Files, but not set by me
    },
    'groupB'  : {
        'someField': 'some value',
        'files': <Group_B_Files>{
            'image': '',
            'bla':  ''
        } // I want to get an error …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript

2
推荐指数
1
解决办法
2631
查看次数

return 带await 和不带await 有区别吗

我只是在想我们需要使用await 运算符,以及以下两种情况有什么区别。

public async updateOne(Model, doc, errorMsg?){
    return await Model.findOneAndUpdate({'_id': doc._id}, {'$set': doc}, {upsert:true, new: true}).lean().exec();
}
Run Code Online (Sandbox Code Playgroud)

public updateOne(Model, doc, errorMsg?){
    return Model.findOneAndUpdate({'_id': doc._id}, {'$set': doc}, {upsert:true, new: true}).lean().exec();
}
Run Code Online (Sandbox Code Playgroud)

我认为结果没有什么区别,但我认为完全没有必要使用 async wait,因为会返回一个 Promise,而我们只需要在 async 函数内调用 updateOne 函数时使用 await 运算符。

javascript asynchronous node.js typescript

1
推荐指数
1
解决办法
3309
查看次数