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

Convert to ESModules & export everything #20

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

NatoBoram
Copy link

@NatoBoram NatoBoram commented Mar 18, 2024

Hi!

While using this package, I needed to import some private types. There were also some imports that were very tricky to use, so I moved the package to ESModules for better compatibility. I also encountered an issue while using Jest; it seems like it's severely outdated as its ESModule support is experimental. Switching to Vitest made it work without having a config file.

With this change, instead of:

import type {
	FunctionDef,
	ObjectProp, // Module '"openai-chat-tokens/dist/functions.js"' declares 'ObjectProp' locally, but it is not exported.
} from "openai-chat-tokens/dist/functions.js"

It's now:

import type { FunctionDef, ObjectProp } from "openai-chat-tokens"

@hellohejinyu
Copy link

import { functionsTokensEstimate } from 'openai-chat-tokens';

type FunctionDef = Parameters<typeof functionsTokensEstimate>[0][number];
type ObjectProp = FunctionDef['parameters'];

Maybe you can try like this.

@NatoBoram
Copy link
Author

Yeah, that's true. I ended up re-publishing the package under https://github.com/coderabbitai/openai-chat-tokens to avoid dealing with more type aliases.

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

Successfully merging this pull request may close these issues.

None yet

2 participants