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

work with BigInt #779

Open
qwer24rus opened this issue Jul 29, 2024 · 2 comments
Open

work with BigInt #779

qwer24rus opened this issue Jul 29, 2024 · 2 comments

Comments

@qwer24rus
Copy link

Hello, I am having problems with BigInt used in action parameters.
For example:
<i class="message-edit" data-action="click->notes#editNote" data-notes-id-param="676280779033907854" data-notes-text-param="test text"></i>
if I check the parameters in action(event.params), I get:
{ id: 676280779033907800, text: 'test text' }
so id now 676280779033907800 instead of 676280779033907854
How can we support BigInt here?

@adrienpoly
Copy link
Member

Numbers are automatically casted using

stimulus/src/core/action.ts

Lines 128 to 134 in e6f1887

function typecast(value: any): any {
try {
return JSON.parse(value)
} catch (o_O) {
return value
}
}

I think we should apply a solution like that

https://stackoverflow.com/questions/69644298/how-to-make-json-parse-to-treat-all-the-numbers-as-bigint

In the mean time best solution is probably to opt out of the params and use a regular data attribute

@qwer24rus
Copy link
Author

qwer24rus commented Jul 29, 2024

Numbers are automatically casted using

stimulus/src/core/action.ts

Lines 128 to 134 in e6f1887

function typecast(value: any): any {
try {
return JSON.parse(value)
} catch (o_O) {
return value
}
}

I'm want to see here somethink like
JSON.parse( value, (_, v) => typeof v === 'bigint' ? BigInt(v) : v)
It will help solve this problem.
But there has to be a better option.

For now i will use your idea with regular data attribute. Thanks.

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

No branches or pull requests

2 participants