openai-chat-tokens icon indicating copy to clipboard operation
openai-chat-tokens copied to clipboard

Convert to ESModules & export everything

Open NatoBoram opened this issue 1 year ago • 2 comments

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"
  • Closes https://github.com/coderabbitai/openai-chat-tokens/pull/1

NatoBoram avatar Mar 18 '24 19:03 NatoBoram

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

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

Maybe you can try like this.

hellohejinyu avatar May 16 '24 02:05 hellohejinyu

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.

NatoBoram avatar May 21 '24 19:05 NatoBoram