pmndrs / maath

🪶 Math helpers for the rest of us
https://maath.pmnd.rs
801 stars 15 forks source link

feat(typescript): add generics to src/random functions to properly infer TypedArray #39

Open mgcrea opened 7 months ago

mgcrea commented 7 months ago

Hey! Thanks for the great lib,

Encountered a few TypeScript issues while using the library with @react-three/drei where props expects a Float32Array.

For instance the following code does not work currently (fails with Argument of type '() => TypedArray' is not assignable to parameter of type 'Float32Array | (() => Float32Array)'.), however the return type should easily be inferred with generics, hence this PR.

  const [sphere] = useState<Float32Array>(() =>
    random.inSphere(new Float32Array(5000), { radius: 1.5 }),
  );
changeset-bot[bot] commented 7 months ago

🦋 Changeset detected

Latest commit: aa4a1baa025d9af6a0ace87c8f36ab975734cd26

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ----- | ----- | | maath | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

vercel[bot] commented 7 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
maath ❌ Failed (Inspect) Nov 16, 2023 8:59pm
codesandbox-ci[bot] commented 7 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit aa4a1baa025d9af6a0ace87c8f36ab975734cd26:

Sandbox Source
maath-demo-circumcircle Configuration
maath-demo-points Configuration
maath-demo-sutherland-hodgman Configuration