TypeScript types not exported correctly
- Dominant language
- TypeScript
- Stars
- 5.3k
- Forks
- 363
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 3
Description
Code works, but `recast` is type `any` instead of `Main`:
```js
const recast = require( 'recast' )
const ast = recast.parse( 'const foo = 1' )
console.log( recast.print( ast ).code )
```
But it gets worse when using it from TypeScript using module syntax:
```ts
import * as recast from 'recast'
const { parse, print } = recast
const ast = parse( 'const foo = 1' )
console.log( print( ast ).code )
```
`Type 'typeof import("xxx/node_modules/recast/main")' has no property 'parse' and no string index signature.`
This makes TypeScript happy, but it fails at runtime:
```ts
import { default as recast } from 'recast'
const { parse, print } = recast
const ast = parse( 'const foo = 1' )
console.log( print( ast ).code )
```
`Cannot destructure property `parse` of 'undefined' or 'null'`
However it does get the correct function signatures for `parse` and `print` in this case, eg `const parse: (source: string, options?: Partial | undefined) => any`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.