asapach / babel-plugin-rewire-exports

Babel plugin for stubbing [ES6, ES2015] module exports
MIT License
66 stars 7 forks source link

Has anybody been able to get this lib to play nicely inside a TS based repo? #31

Closed glomotion closed 3 years ago

glomotion commented 3 years ago

so we have a demo repo here: https://github.com/glomotion/stripped-down-next-rewire-ts/tree/tryout/rewire-exports

We're just wondering if anyone has managed to get this lib working well inside a TS repo? It'd be SUPER nice to be able to use TS alongside this lib.

Screen Shot 2021-07-25 at 11 21 15 am
asapach commented 3 years ago

I don't think there is a good way to let TS know about the missing types, because they depend on the exports, so I'm afraid the only option I see is to ignore the types entirely. Something like this should work:

import * as MooComponent from './Moo.component';

(MooComponent as any).rewire$Moo();
glomotion commented 3 years ago

Yeah I figured as much. Writing tests using jsx instead of ts isn’t the end of the world anyway, IMO. Thanks for the quick reply! :)