6

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?

antjanus
  • 987
  • 3
  • 15
  • 30
  • you don't have typedefs for showdown, do you? if you don't, then cast like `(showdown).Converter()` – YOU Oct 17 '15 at 04:48
  • may be better install this def with tsd - https://github.com/borisyankov/DefinitelyTyped/tree/master/showdown – YOU Oct 17 '15 at 04:51
  • I do have them installed. I accidentally linked the wrong repo. I have a typings folder with showdown/showdown.d.ts and all of it is referenced in tsd.d.ts which I'm referencing in the file I listed above. – antjanus Oct 17 '15 at 07:04
  • The `(showdown).Converter()` didn't work. @YOU any other ideas? – antjanus Oct 19 '15 at 12:45
  • same error? or something else. – YOU Oct 19 '15 at 13:11
  • 1
    same error. I switched from Showdown to Marked and it works flawlessly. No clue why. – antjanus Oct 20 '15 at 00:15

1 Answers1

3

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.

Liz Bennett
  • 831
  • 9
  • 22