Home > database >  Typescript requires mithril import that breaks in javascript
Typescript requires mithril import that breaks in javascript

Time:07-20

Currently translating my javascript app to typescript. Previously I was just using m() and Vnode without any imports, but typescript wants needs to include import m, { Vnode } from 'mithril'; so it knows what they are.

The problem is when this compiles it adds the import m from 'mithril'; to the top of the new js file. For some reason having that import breaks the app. I'm not entirely sure how it's able to work without that import, or why the import breaks it. This is for a chrome extension, and the error logging is very unhelpful, so I don't know what the specific error even is. The app just whitescreens.

Currently I am trying to fix this problem by writing a script that just deletes that import from every file, but I was wondering if there was a way to either omit that import in the first place/not have it break the javascript.

CodePudding user response:

add the typings repo for this library: e.g. yarn add @types/mithril

Example repo that uses mithril and the typing lib, including the m import https://github.com/spacejack/mithril-ts-example

CodePudding user response:

Solved this by just putting

declare let m: any;

at the top of my file and hoping I'm using m right. This satisfies the typescript and doesn't get translated into the JS

  • Related