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

Typescript destructure import support #98

Open
justin-hackin opened this issue Oct 13, 2021 · 2 comments
Open

Typescript destructure import support #98

justin-hackin opened this issue Oct 13, 2021 · 2 comments

Comments

@justin-hackin
Copy link

justin-hackin commented Oct 13, 2021

I'm not sure why the type definitions aren't working when destructuring the default import but I always get TS2614 error when importing

Module '"../node_modules/@flatten-js/core"' has no exported member 'Line'. Did you mean to use 'import Line from "../node_modules/@flatten-js/core"' instead?ts(2614)

Here's a reproduction: https://codesandbox.io/s/dark-sound-r7148?file=/src/index.ts

It's been like this since I started using the package several years ago.

@justin-hackin justin-hackin changed the title Typescript definitions not recognized Typescript destructure import support Oct 13, 2021
@justin-hackin
Copy link
Author

I noticed that you can work around this by const-destructuring the imports like this: https://codesandbox.io/s/infallible-solomon-tyj8p?file=/src/index.ts . Perhaps this warrants a notice in the readme

@verekia
Copy link

verekia commented Sep 12, 2022

This is how I fix it with re-exports:

flatten.ts

// This file exists to fix destructured imports in Flatten
// https://github.com/alexbol99/flatten-js/issues/98

import Flatten from '@flatten-js/core'

const {
  Box,
  Point,
  Ray,
  Vector,
  Segment,
  point,
  circle,
  // @ts-ignore
  box,
  segment,
} = Flatten
export type FlattenBox = Flatten.Box
export type FlattenPoint = Flatten.Point
export type FlattenRay = Flatten.Ray
export type FlattenVector = Flatten.Vector
export type FlattenSegment = Flatten.Segment
export type FlattenCircle = Flatten.Circle

// Missing in their typedefs
type box = (xmin?: number, ymin?: number, xmax?: number, ymax?: number) => FlattenBox

export { Box, Point, Ray, Vector, Segment, point, circle, box, segment }

(add all the shapes you need)

Then I can do :

import { box, FlattenBox } from './flatten'

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

No branches or pull requests

3 participants