Skip to content

Fix TypeScript definitions to match actual module export#24

Open
a-skindzer wants to merge 6 commits into
bd808:mainfrom
a-skindzer:fix/phpunserialize-import-error
Open

Fix TypeScript definitions to match actual module export#24
a-skindzer wants to merge 6 commits into
bd808:mainfrom
a-skindzer:fix/phpunserialize-import-error

Conversation

@a-skindzer

Copy link
Copy Markdown

Issue

The TypeScript definition file declares a named export:

export function phpUnserialize(phpstr: string): unserialized;

However, the actual JavaScript module exports a function as the default export.
This mismatch causes a runtime error when TypeScript users try to import and use the function:

import { phpUnserialize } from "phpunserialize"; // TypeScript thinks this works
phpUnserialize(data); // Runtime error: not a function

Solution:

Update the TypeScript definitions to represent the default export correctly:

export type unserialized = phpscalar | phparray;
declare function phpUnserialize(phpstr: string): unserialized;
export default phpUnserialize;

This allows the correct usage:

import phpUnserialize from "phpunserialize";
phpUnserialize(data); // Works correctly

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.

1 participant