wheatjs / vite-plugin-vue-type-imports

Import types in Vue SFC for defineProps
223 stars 18 forks source link

Redeclaration of Types #6

Closed bcakmakoglu closed 2 years ago

bcakmakoglu commented 2 years ago

I get the following error when I try to import an interface which uses a Type that is equal to another type.

If it's relevant, I'm on Mac (M1) BigSur.

# package.json
{
 "devDependencies": {
    "@vitejs/plugin-vue": "^1.9.3",
    "@vue/compiler-sfc": "3.2.22",
    "typescript": "^4.4.4",
    "vite": "2.5.x",
    "vite-plugin-vue-type-imports": "^0.1.2",
    "vue": "3.2.22",
    "vue-tsc": "^0.29.5"
  },
}
image
type Foo = [[number, number], [number, number]]
type Bar = Foo

interface Props {
   foo: Foo
   bar: Bar
}

When I change it to

type Foo = [[number, number], [number, number]]
type Bar = [[number, number], [number, number]]

interface Props {
   foo: Foo
   bar: Bar
}

it works properly.

For obvious reasons it would be nice if the first implementation worked as well :)

Thanks for the plugin though, it helps remove a lot of duplicated code 👍

wheatjs commented 2 years ago

Oh this is a good catch, thanks! I'll get a fix out soon

wheatjs commented 2 years ago

Hey, I've had some trouble reproducing this. Could you provide a reproduction?

bcakmakoglu commented 2 years ago

@wheatjs Tbh i can't seem to reproduce the issue in a sandbox for some reason.

When I try something like this

type StringFunc<N = any> = (node: Node<N> | GraphNode<N>) => string

interface MiniMapProps<N = any> {
  nodeColor?: string | StringFunc<N>
  nodeStrokeColor?: string | StringFunc<N>
  nodeClassName?: string | StringFunc<N>
  nodeBorderRadius?: number
  nodeStrokeWidth?: number
  maskColor?: string
}

I end up with the error that StringFunc is declared multiple times.

image

In other instances this exact schema does work though, for example my original Issue showed an example where I tried using

type Foo = [[number, number], [number, number]]
type Bar = Foo

interface Props {
   foo: Foo
   bar: Bar
}

which resulted in an error. Somehow that issue resolved itself though and I am not really sure why 😅 I didn't actually change anything regarding the implementation or the types.

Also I noticed that using

interface PropsBase {
  foo: string
  bar: number
}

interface Props extends PropsBase {
  baz: boolean
}

doesn't work - it doesn't throw any errors as far as I can tell but the props aren't defined i.e. inside the component the fields are never defined even though values are passed.

Could there be an issue with me using Vue@^3.2.22?

Other than that I am a little at a loss on how to replicate the issue :(