Skip to content

Commit

Permalink
Update type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Dodge committed Sep 4, 2020
1 parent 15fe1b7 commit a1ffa74
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 31 deletions.
6 changes: 1 addition & 5 deletions templates/library/library.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<% if (version === 3) { -%>
import { defineComponent, Plugin } from 'vue';

type InstallFunction = Plugin['install'] & { installed?: boolean }
<% } else { -%>
import Vue, { PluginFunction, VueConstructor } from 'vue';

interface InstallFunction extends PluginFunction<any> {
installed?: boolean;
}
<% } -%>

declare const <%-componentNamePascal%>: { install: InstallFunction };
declare const <%-componentNamePascal%>: { install: <% if (version === 3) { %>Plugin['install']<% } else { %>PluginFunction<any><% } %> };
export default <%-componentNamePascal%>;

export const <%-componentNamePascal%>Sample: <% if (version === 3) { %>ReturnType<typeof defineComponent><% } else { %>VueConstructor<Vue><% } %>;
13 changes: 1 addition & 12 deletions templates/library/src/entry.esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,12 @@ import _Vue, { PluginFunction, PluginObject } from 'vue';
// Import vue components
import * as components from '@/lib-components/index';

<% if (ts) { -%>
// Define typescript interfaces for autoinstaller
<% if (version === 3) { -%>
type InstallFunction = Plugin['install'] & { installed?: boolean }
<% } else { -%>
type InstallFunction = PluginFunction<any> & { installed?: boolean }
<% } -%>

<% } -%>
// install function executed by Vue.use()
<% if (ts) { -%>
const install: InstallFunction = function install<%-componentNamePascal%>(<% if (version === 3) { %>app: App<% } else { %>Vue: typeof _Vue<% } %>) {
const install: <% if (version === 3) { %>Plugin['install']<% } else { %>PluginFunction<any><% } %> = function install<%-componentNamePascal%>(<% if (version === 3) { %>app: App<% } else { %>Vue: typeof _Vue<% } %>) {
<% } else { -%>
const install = function install<%-componentNamePascal%>(<% if (version === 3) { %>app<% } else { %>Vue<% } %>) {
<% } -%>
if (install.installed) return;
install.installed = true;
Object.entries(components).forEach(([componentName, component]) => {
<% if (version === 3) { %>app<% } else { %>Vue<% } %>.component(componentName, component);
});
Expand Down
8 changes: 2 additions & 6 deletions templates/single/single-component.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<% if (version === 3) { -%>
import { defineComponent, Plugin } from 'vue';

type InstallFunction = Plugin['install'] & { installed?: boolean }
type InstallableComponent = ReturnType<typeof defineComponent> & { install: InstallFunction };
type InstallableComponent = ReturnType<typeof defineComponent> & { install: Plugin['install'] };
<% } else { -%>
import Vue, { PluginFunction, VueConstructor } from 'vue';

interface InstallFunction extends PluginFunction<any> {
installed?: boolean;
}
export interface InstallableComponent extends VueConstructor<Vue> {
install: InstallFunction;
install: PluginFunction<any>;
}
<% } -%>

Expand Down
8 changes: 2 additions & 6 deletions templates/single/src/entry.esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import component from '@/<%-componentName%>.vue';
<% if (ts) { -%>
// Define typescript interfaces for installable component
<% if (version === 3) { -%>
type InstallFunction = Plugin['install'] & { installed?: boolean }
type InstallableComponent = ReturnType<typeof defineComponent> & { install: InstallFunction };
type InstallableComponent = ReturnType<typeof defineComponent> & { install: Plugin['install'] };
<% } else { -%>
type InstallFunction = PluginFunction<any> & { installed?: boolean }
type InstallableComponent = VueConstructor<_Vue> & PluginObject<any>;
<% } -%>

<% } -%>
// install function executed by Vue.use()
<% if (ts) { -%>
const install: InstallFunction = function install<%-componentNamePascal%>(<% if (version === 3) { %>app: App<% } else { %>Vue: typeof _Vue<% } %>) {
const install: <% if (version === 3) { %>Plugin['install']<% } else { %>PluginFunction<any><% } %> = function install<%-componentNamePascal%>(<% if (version === 3) { %>app: App<% } else { %>Vue: typeof _Vue<% } %>) {
<% } else { -%>
const install = function install<%-componentNamePascal%>(<% if (version === 3) { %>app<% } else { %>Vue<% } %>) {
<% } -%>
if (install.installed) return;
install.installed = true;
<% if (version === 3) { %>app<% } else { %>Vue<% } %>.component('<%-componentNamePascal%>', component);
};

Expand Down
6 changes: 4 additions & 2 deletions templates/single/src/entry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// iife/cjs usage extends esm default export - so import it all
import component /* , { RollupDemoDirective } */ from '@/entry.esm';
import component, * as namedExports from '@/entry.esm';

// Attach named exports directly to component. IIFE/CJS will
// only expose one global var, with named exports exposed as properties of
// that global var (eg. VivintIcon.iconList)
// component.RollupDemoDirective = RollupDemoDirective;
Object.entries(namedExports).forEach(([exportName, exported]) => {
if (exportName !== 'default') component[exportName] = exported;
});

export default component;

0 comments on commit a1ffa74

Please sign in to comment.