Polymer LitElement TS示例的编译问题

Polymer LitElement TS示例的编译问题,polymer,lit-element,Polymer,Lit Element,你好聚合物社区: 这里的新用户在使用TS的lit元素时遇到了一些问题,但不确定原因 我有TS设置和工作良好(编译其他TS示例) npm是否按照入门页面安装了lit元素 在“使用LitElement TypeScript装饰器”一节中尝试TS示例,并得到各种不好的结果 tsc my-element.ts导致完全失败: my-element.ts:14:14 - error TS1219: Experimental support for decorators is a feature that

你好聚合物社区:

这里的新用户在使用TS的lit元素时遇到了一些问题,但不确定原因

我有TS设置和工作良好(编译其他TS示例)

npm是否按照入门页面安装了lit元素

在“使用LitElement TypeScript装饰器”一节中尝试TS示例,并得到各种不好的结果

tsc my-element.ts导致完全失败:

my-element.ts:14:14 - error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.

14 export class MyElement extends LitElement {

my-element.ts:20:3 - error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.

20   foo = 'foo';

node_modules/lit-element/lib/updating-element.d.ts:102:38 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

102 export declare type PropertyValues = Map<PropertyKey, unknown>;

node_modules/lit-html/lib/parts.d.ts:18:63 - error TS2304: Cannot find name 'Iterable'.

18 export declare const isIterable: (value: unknown) => value is Iterable<unknown>;

node_modules/lit-html/lib/render.d.ts:16:29 - error TS2583: Cannot find name 'WeakMap'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

16 export declare const parts: WeakMap<Node, NodePart>;

node_modules/lit-html/lib/template-factory.d.ts:56:28 - error TS2583: Cannot find name 'WeakMap'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

56     readonly stringsArray: WeakMap<TemplateStringsArray, Template>;

node_modules/lit-html/lib/template-factory.d.ts:57:25 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

57     readonly keyString: Map<string, Template>;

node_modules/lit-html/lib/template-factory.d.ts:59:38 - error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.

59 export declare const templateCaches: Map<string, templateCache>;

Found 8 errors.
我也尝试过没有tsconfig文件。同样的结果

请善良的人们帮我指出正确的方向。 非常感谢。
David

我在使用TypeScript编译器的3.9.3版时遇到了类似的问题,我通过使用tsconfig.json成功地解决了这个问题:

{
  "compilerOptions": {
    "target": "es2015",
    "lib": ["es2015"],
    "module": "commonjs",
    "experimentalDecorators": true
  }
}

您需要在
tsconfig.json
中包含
dom
库:

{
    "compilerOptions": {
        ...,
        "lib": [
            ...,
            "dom"
        ]
    }
}
{
    "compilerOptions": {
        ...,
        "lib": [
            ...,
            "dom"
        ]
    }
}