Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using TypeScript with webpack and ES6. I'm trying to import the module Showdown and use it to convert markdown to HTML. Here's my app.ts code:

/// <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:

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. Angular loads up fine but Showdown seems to be having trouble. The Showdown type file seems to be correct (including the property Converter) and from what I can understand, it loads up fine.

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.

Any ideas?

like image 566
antjanus Avatar asked Oct 17 '15 04:10

antjanus


1 Answers

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.

like image 82
Liz Bennett Avatar answered Oct 23 '22 03:10

Liz Bennett