简体   繁体   English

即使包含类型文件,Typescript也会抛出属性上不存在的属性

[英]Typescript throws a property does not exist on type even with type file included

I'm using TypeScript with webpack and ES6. 我正在使用带有webpack和ES6的TypeScript。 I'm trying to import the module Showdown and use it to convert markdown to HTML. 我正在尝试导入模块Showdown并使用它将markdown转换为HTML。 Here's my app.ts code: 这是我的app.ts代码:

/// <reference path="../typings/tsd.d.ts" />

import 'zone.js';
import 'reflect-metadata';
import 'es6-shim';

import * as showdown from 'showdown';

import {Component, View, bootstrap} from 'angular2/angular2';

@Component({
  selector: 'markdown-app'
})
@View({
  templateUrl: '/app/markdownApp.html'
})
class MarkdownAppComponent {
  public html: string;
  private md: any;

  constructor() {
    this.html = '';
    this.md = showdown.Converter();
  }

  public updateValue(val) {
    this.html = this.md.makeHtml(val);
  }
}

bootstrap(MarkdownAppComponent);

When I try to convert TS to ES6, I get the following error: 当我尝试将TS转换为ES6时,我收到以下错误:

ERROR in ./src/app/app.ts
(23,24): error TS2339: Property 'Converter' does not exist on type 'typeof Showdown'.

I'm using TSD to install all of the type definitions. 我正在使用TSD来安装所有类型定义。 Angular loads up fine but Showdown seems to be having trouble. Angular加载很好,但Showdown似乎遇到了麻烦。 The Showdown type file seems to be correct (including the property Converter) and from what I can understand, it loads up fine. Showdown类型文件似乎是正确的(包括属性Converter),根据我的理解,它加载正常。

I console logged out the showdown variable to make sure that Showdown did indeed get importer and it did, and it has the Converter property. 我控制台注销了showdown变量以确保Showdown确实获得了导入器并且确实如此,并且它具有Converter属性。

Any ideas? 有任何想法吗?

I ran into a similar issue and I had to do: 我遇到了类似的问题,我必须这样做:

this.md = new showdown.Converter();

instead of 代替

this.md = showdown.Converter();

Looks like you solved your problem a while ago, but in case anyone runs into this issue I figured I'd throw my solution up here. 看起来你刚刚解决了你的问题,但万一有人遇到这个问题,我想我会把我的解决方案扔到这里。

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

相关问题 属性在类型上不存在。打字稿 - Property does not exist on type. TypeScript 错误“类型为&#39;IAugmentedJQuery&#39;的Typescript不存在属性&#39;datepicker&#39; - error "Property 'datepicker' does not exist on type 'IAugmentedJQuery' With Typescript 解决打字稿错误的最佳方法 - 类型上不存在属性 - Best way to solve typescript error - property does not exist on type 打字稿错误:&#39;HTMLElement&#39;类型中不存在属性&#39;append&#39; - Typescript Error: Property 'append' does not exist on type 'HTMLElement' TypeScript构建错误:“ IStateParamsService”类型不存在属性 - TypeScript Build Error : Property does not exist on type 'IStateParamsService' 类型“#”错误中不存在属性“#” - Property "#" does not exist on type "#" error 属性“ requestOptions”在类型上不存在 - Property 'requestOptions' does not exist on type 类型“Observable”上不存在“finally”属性<Object> &#39; - Property 'finally' does not exist on type 'Observable<Object>' &#39;typeof Foods&#39;类型不存在属性&#39;id&#39; - Property 'id' does not exist on type 'typeof Foods' “IAngularStatic”类型上不存在属性“模拟” - Property 'mock' does not exist on type 'IAngularStatic'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM