Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item typing not exported in TS declaration file #35

Closed
mrjpierce opened this issue Jun 28, 2019 · 8 comments
Closed

Item typing not exported in TS declaration file #35

mrjpierce opened this issue Jun 28, 2019 · 8 comments

Comments

@mrjpierce
Copy link

Currently running into this problem after last release:

import PO, { Item } from 'pofile'; // Cannot export Item

private doSomething(str: string): PO.Item { // Error, cant use PO type as namespace to get item Type

	const item = new PO.Item(); // Works fine.
	item.msgid = str;
	return item;
}

Probably going to have the same issue with the Header type

@rubenv
Copy link
Owner

rubenv commented Jun 28, 2019

I'm no expert on TypeScript typings, so I can't really say for sure what the fix is.

@septs Can you have a look at this?

@septs
Copy link
Contributor

septs commented Jun 28, 2019

@mrjpierce first, this package not is esmodule
The as designed,

module.exports = PO;

@rubenv the issue require use esmodule written this package
WARNING: This needs to break the API backwards compatibility

see https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require

@septs
Copy link
Contributor

septs commented Jun 28, 2019

About get PO.Item instance type, please use the workaround code

type Item = InstanceType<typeof PO["Item"]>

See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#conditional-types

@mrjpierce
Copy link
Author

@septs

type Item = typeof PO["Item"]["prototype"];

This seems to work for now 👍. Xièxiè

@septs
Copy link
Contributor

septs commented Jun 29, 2019

@rubenv The issue closable

@rubenv
Copy link
Owner

rubenv commented Jun 29, 2019

@septs thanks!

@septs
Copy link
Contributor

septs commented Sep 15, 2019

@rubenv I want to rewrite this codebase using TypeScript.

@rubenv
Copy link
Owner

rubenv commented Sep 16, 2019

@septs Could you elaborate a bit on why and how you'd want to do this?

Keep in mind that this is a project I consider "finished": no big new functionality is needed (it does what it needs to do) and we can't break API / backwards compatibilty.

Rewrites are always risky. I'm all for strongly typing things, but it can only be done incrementally and in an extremely careful way: no user should ever see their code break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants