maath icon indicating copy to clipboard operation
maath copied to clipboard

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

Open mgcrea opened this issue 2 years ago • 3 comments

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 }),
  );

mgcrea avatar Nov 16 '23 19:11 mgcrea

🦋 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

changeset-bot[bot] avatar Nov 16 '23 19:11 changeset-bot[bot]

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

vercel[bot] avatar Nov 16 '23 19:11 vercel[bot]

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

codesandbox-ci[bot] avatar Nov 16 '23 19:11 codesandbox-ci[bot]