flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.02k stars 87 forks source link

Fix compilation error with typescript 5 #230

Closed darthmaim closed 1 year ago

darthmaim commented 1 year ago

When using typescript 5 in a project using superjson the build fails with the following error:

./node_modules/superjson/src/accessDeep.ts:102:5
Type error: Element implicitly has an 'any' type because expression of type 'string | number' can't be used to index type 'any[] | { [key: string]: any; }'.
  No index signature with a parameter of type 'string' was found on type 'any[] | { [key: string]: any; }'.

  100 | 
  101 |   if (isArray(parent) || isPlainObject(parent)) {
> 102 |     parent[lastKey] = mapper(parent[lastKey]);
      |     ^
  103 |   }
  104 | 
  105 |   if (isSet(parent)) {

This change fixes this error.

Skn0tt commented 1 year ago

Nice, thank you!

Skn0tt commented 1 year ago

What's interesting to me is that your project seems to be importing the .ts files - that's surprising me, I'd have expected all projects to be using the dist/index.js file. Is that a special config option you did?

Skn0tt commented 1 year ago

@all-contributors please add @darthmaim for code

allcontributors[bot] commented 1 year ago

@Skn0tt

I've put up a pull request to add @darthmaim! :tada:

Skn0tt commented 1 year ago

published this PR in https://github.com/blitz-js/superjson/releases/tag/v1.12.3.

darthmaim commented 1 year ago

What's interesting to me is that your project seems to be importing the .ts files - that's surprising me, I'd have expected all projects to be using the dist/index.js file. Is that a special config option you did?

No, I would also have expected this, but its just a default next.js project with next-superjson-plugin, I am not even using superjson directly

Here is the tsconfig if you are interested: https://github.com/GW2Treasures/gw2treasures.com/blob/main/apps/web/tsconfig.json And here the PR to update to TS5 which currently fails: https://github.com/GW2Treasures/gw2treasures.com/pull/122

Thanks for merging this PR ❤️