Aaronius / penpal

A promise-based library for securely communicating with iframes via postMessage.
MIT License
381 stars 56 forks source link

Export types #67

Closed olee closed 3 years ago

olee commented 3 years ago

Hi, I just wanted to start using this library with typescript, but immediately noticed a big issue: Types like Connection do not seem to be exported at all from this library. In fact, the only export seems to be connectToChild, connectToParent and ErrorCode.

At least the generic type Connection would be highly required to properly type fields

Aaronius commented 3 years ago

Hey @olee. Thanks for reporting this. Is this something you'd want to help with or not so much? No pressure either way.

Aaronius commented 3 years ago

@olee, the types are exported and can be found in penpal/lib/types, so you should be able to import them like so:

import { Connection } from 'penpal/lib/types';

Are you not able to do that or were you expecting something different? Frankly, I'm not terribly familiar with TypeScript conventions for publishing libraries, so if you see Penpal doing something that's not conventional, please let me know so I can correct it.

Thanks for creating the issue.

Aaronius commented 3 years ago

@lpellegr, maybe this is something you can chime in on as well. I want to make sure we're exporting types in a way that's standard for the TypeScript community so that developers like @olee can more easily find them. If it seems like we're doing it the conventional way, then I probably just need to update documentation to be more clear about how to import the types.

olee commented 3 years ago

Well, it is possible to import from the child path, however that is not really the recommended behavior, especially since everything else in this library can be imported from the index.

To solve this issue, a simple

export * from './types';

inside index.ts would solve this and at the same time greatly simplify working with the types in this library.

Aaronius commented 3 years ago

Makes sense. Thank you.

Aaronius commented 3 years ago

This was released in v6. Thanks!