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

Add Package Types #19

Closed
wants to merge 2 commits into from
Closed

Conversation

alexsasharegan
Copy link

Closes #10

@LinusBorg LinusBorg self-requested a review June 8, 2019 23:20
@LinusBorg LinusBorg self-assigned this Jun 8, 2019
@LinusBorg
Copy link
Owner

Thanks :)

Will need to find some time to test this and possibly try and add actual types for the ``Portalcomponent instead ofany`, but this is immensly helpful :)

@alexsasharegan
Copy link
Author

Yeah, SFC's are shimmed as any in the Vue CLI, and I think it tends to avoid more problems than it would solve by being typed as a proper component, but I would love to know if there's a better way.

@alexsasharegan
Copy link
Author

Here's one possible way to type the component, but it has the drawback of advertising internal methods:

import Vue, { Component, PluginFunction } from 'vue'

export interface SimplePortalOptions {
  name?: string
}

export interface SimplePortalConfig {
  selector: string
}

export var config: Readonly<SimplePortalConfig>
export var setSelector: <T extends string>(selector: T) => T

interface PortalMethods {
  getTargetEl(): void | HTMLElement | null
  insertTargetEl(): void
  mount(): void
  unmount(): void
}

export interface PortalProps {
  disabled?: boolean
  prepend?: boolean
  selector?: string
  tag?: string
}

export var Portal: Component<void, PortalMethods, void, PortalProps>

var install: PluginFunction<SimplePortalOptions>
export default install

@fuzzzerd
Copy link

Any chance of this getting merged and pushed as a package update? Typescript support would be useful.

@sattes-faction
Copy link

Hello guys,
any chance that this is going to be merged?

@Finrod927
Copy link

For those who need TS definition, you can create a .d.ts file in your src folder with that definition, it should work:

declare module '@linusborg/vue-simple-portal' {
  import { PluginFunction } from 'vue'

  export interface SimplePortalOptions {
    name?: string
  }

  export interface SimplePortalConfig {
    selector: string
  }

  export const config: Readonly<SimplePortalConfig>
  export const setSelector: <T extends string>(selector: T) => T
  export const Portal: any

  const install: PluginFunction<SimplePortalOptions>
  export default install
}

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

Successfully merging this pull request may close these issues.

Typescript definitions
5 participants