简体   繁体   English

TypeScript-尝试调用超级setter / getter时出错(仅通过prod任务重现)

[英]TypeScript - Error when try to call super setter/getter (reproduce only with prod task)

When I try call super getter or super setter when overriding properties? 当我尝试覆盖属性时调用超级getter或超级setter时? I get an error: TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. 我收到一个错误:TS2340:通过'super'关键字只能访问基类的公共和受保护的方法。

This error I get only when execute 'ng build --configuration=production --stats-json' 仅在执行'ng build --configuration = production --stats-json'时出现此错误

This error appeared after the I update Angular from v7.2.11 to v8.0.3 (TypeScrypt from v3.1.6 to v3.4.5). 我将Angular从v7.2.11更新到v8.0.3(将TypeScrypt从v3.1.6更新到v3.4.5)后出现了此错误。

With Angular v7.2.11 and TypeScrypt v3.1.6 there is no such error. 使用Angular v7.2.11和TypeScrypt v3.1.6时,不会出现此类错误。 I don't use targeting to es5. 我不使用针对es5的定位。 I tried to target es2015, es2016, es2017, but I get the same error in each case. 我尝试将es2015,es2016,es2017定位为目标,但在每种情况下都遇到相同的错误。

Code example 代码示例

export abstract class ChildComponent extends ParentComponent {
    get selected(): boolean {
        return super.selected;
    }
    set selected(selected: boolean) {
        super.selected = selected;
    }
}
export abstract class ParentComponent {
    public get selected(): boolean {
        return this._selected;
    }
    public set selected(value: boolean) {
        this._selected = value;
    }
}

My tsconfig: 我的tsconfig:

{
        "compileOnSave": false,
        "compilerOptions": {
                "downlevelIteration": true,
                "outDir": "./dist",
                "baseUrl": ".",
                "sourceMap": true,
                "declaration": false,
                "moduleResolution": "node",
                "module": "esnext",
                "emitDecoratorMetadata": true,
                "experimentalDecorators": true,
                "noEmitHelpers": true,
                "importHelpers": true,
                "esModuleInterop": true,
                "target": "es2015",
                "typeRoots": [
                       "node_modules/@types"
                ],
                "lib": [
                       "es2017",
                       "dom"
                ],
                "paths": {
                   ...
                }
        },
        "exclude": [
        ...
       ]
}

I expected my code to start working after I switched to “target”: “es2015”, but it didn't. 我希望我的代码在切换到“ target”:“ es2015”后就可以开始工作,但事实并非如此。 Maybe there is any errors in my config? 也许我的配置中有任何错误?

I also do not use the arrow functions, so as far as I understand, my problem is not related to the context. 我也不使用箭头功能,据我了解,我的问题与上下文无关。

In Angular CLI version 8 and higher, differential loading is enabled by default for the ng build command . 在Angular CLI版本8和更高版本中,ng build命令默认启用差异加载 As a result, this produces two builds, and differential loading is enabled. 结果,这产生两个构建,并启用了差异加载。 If you ignore browsers without ES2015 support, a single build is produced. 如果您忽略不支持ES2015的浏览器,则会生成一个内部版本。

You can do this by setting .browserlistrc to ignore or include browsers that you needed. 您可以通过将.browserlistrc设置为忽略或包括所需的浏览器来完成此操作。 Otherwise you can add the "browserslist" field to your package.json . 否则,您可以将“ browserslist”字段添加到package.json中

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

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