jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.65k stars 514 forks source link

TypeError: generalize is not a function #1227

Open kirevdokimov opened 1 year ago

kirevdokimov commented 1 year ago

Expected Behavior

A. Named import of "generalize" should be referencing to an existing js counterpart B. Default import from "@jscad/modeling/src/operations/modifiers/generalize" must be typed

Actual Behavior

A. Named import of "generalize" is typed properly, but referencing to nowhere.

TypeError: (0 , import_generalize.generalize) is not a function

B. Default import works perfectly, but not typed therefore marked as an error by tsc

Steps to Reproduce the Problem

A.

1.Create a typescript file

// namedimport.ts
import { generalize } from "@jscad/modeling/src/operations/modifiers/generalize"
import { cube } from "@jscad/modeling/src/primitives"

generalize({triangulate: true}, cube())

2.Bundle the script.

esbuild namedimport.ts --platform=browser --format=esm --target=esnext --bundle=true

3.Run it.

B.

  1. Create a typescript file
    
    // defaultimport.ts
    import generalize from "@jscad/modeling/src/operations/modifiers/generalize"
    import { cube } from "@jscad/modeling/src/primitives"

generalize({triangulate: true}, cube())



2. Open in an editor with a typescript installed
<img width="892" alt="image" src="https://user-images.githubusercontent.com/5202070/230755582-b6366af6-f3c3-437b-ae70-dbf4b4c1d6ed.png">

## Specifications

  - Version: 2.11.0
  - Platform: browser
  - Environment: (browser, local server, node.js etc) browser + esbuild + typescript
kirevdokimov commented 1 year ago

Temporary solution is to import default and cast to an unknown

import generalize from "@jscad/modeling/src/operations/modifiers/generalize"

...

const generalizedpolyh = (generalize as unknown as any)({ triangulate: true }, polyh);
z3dev commented 1 year ago

Actually, the solution is fixing the TS definition.