Skip to content

Commit f0c837c

Browse files
michaeltintiucgrgur
authored andcommitted
Improve typescript typings and config (#44)
1 parent 35d3038 commit f0c837c

29 files changed

+332
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_modules/
66
coverage/
77
reports/
88
src/**/*.js
9+
types/**/*.map
910

1011
# ignore log files
1112
*.log

build/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function baseConfig() {
5252
'@ionic/core/dist/ionic/svg',
5353
'ionicons/dist/collection/icon/icon.css',
5454
],
55-
plugins: [vue(), typescript()],
55+
plugins: [vue(), typescript({ useTsconfigDeclarationDir: true })],
5656
}
5757
}
5858

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
"license": "MIT",
99
"repository": "github:ModusCreateOrg/ionic-vue",
1010
"main": "dist/ionic-vue.common.js",
11-
"typings": "dist/index.d.ts",
11+
"typings": "types/index.d.ts",
1212
"module": "dist/ionic-vue.esm.js",
1313
"unpkg": "dist/ionic-vue.js",
1414
"jsdelivr": "dist/ionic-vue.js",
1515
"files": [
1616
"src/",
17+
"types/",
1718
"dist/*.js",
1819
"dist/*.ts"
1920
],

src/api-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTMLStencilElement } from './types/interfaces';
1+
import { HTMLStencilElement } from './interfaces';
22

33
// A proxy method that initializes the controller and calls requested method
44
export function proxyMethod(tag: string, method: string, ...opts: any[]): Promise<any> {

src/api.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Vue, { PluginFunction } from 'vue';
2-
import { ApiCache, FrameworkDelegate } from './types/interfaces';
2+
import { ApiCache, FrameworkDelegate } from './interfaces';
33
import Delegate from './framework-delegate';
44
import ProxyController from './proxy-controller';
55
import ProxyMenuController from './proxy-menu-controller';
@@ -13,37 +13,37 @@ export default class Api {
1313
static install: PluginFunction<never>;
1414

1515
// Create or return a ActionSheetController instance
16-
get actionSheetController(): typeof ProxyController {
16+
get actionSheetController(): ProxyController {
1717
return getOrCreateController('ion-action-sheet-controller');
1818
}
1919

2020
// Create or return an AlertController instance
21-
get alertController(): typeof ProxyController {
21+
get alertController(): ProxyController {
2222
return getOrCreateController('ion-alert-controller');
2323
}
2424

2525
// Create or return a LoadingController instance
26-
get loadingController(): typeof ProxyController {
26+
get loadingController(): ProxyController {
2727
return getOrCreateController('ion-loading-controller');
2828
}
2929

3030
// Create or return a MenuController instance
31-
get menuController(): typeof ProxyMenuController {
31+
get menuController(): ProxyMenuController {
3232
return getOrCreateMenuController('ion-menu-controller');
3333
}
3434

3535
// Create or return a ModalController instance
36-
get modalController(): typeof ProxyDelegateController {
36+
get modalController(): ProxyDelegateController {
3737
return getOrCreateDelegatedController('ion-modal-controller');
3838
}
3939

4040
// Create or return a PopoverController instance
41-
get popoverController(): typeof ProxyDelegateController {
41+
get popoverController(): ProxyDelegateController {
4242
return getOrCreateDelegatedController('ion-popover-controller');
4343
}
4444

4545
// Create or return a ToastController instance
46-
get toastController(): typeof ProxyController {
46+
get toastController(): ProxyController {
4747
return getOrCreateController('ion-toast-controller');
4848
}
4949
}
@@ -82,7 +82,7 @@ Api.install = (Vue): void => {
8282
};
8383

8484
// Get existing Base controller instance or initialize a new one
85-
function getOrCreateController(tag: string): typeof ProxyController {
85+
function getOrCreateController(tag: string): ProxyController {
8686
if (!Api.cache[tag]) {
8787
Api.cache[tag] = new ProxyController(tag);
8888
}
@@ -91,7 +91,7 @@ function getOrCreateController(tag: string): typeof ProxyController {
9191
}
9292

9393
// Get existing Menu controller instance or initialize a new one
94-
function getOrCreateMenuController(tag: string): typeof ProxyMenuController {
94+
function getOrCreateMenuController(tag: string): ProxyMenuController {
9595
if (!Api.cache[tag]) {
9696
Api.cache[tag] = new ProxyMenuController(tag);
9797
}
@@ -100,7 +100,7 @@ function getOrCreateMenuController(tag: string): typeof ProxyMenuController {
100100
}
101101

102102
// Get existing Delegated controller instance or initialize a new one
103-
function getOrCreateDelegatedController(tag: string): typeof ProxyDelegateController {
103+
function getOrCreateDelegatedController(tag: string): ProxyDelegateController {
104104
if (!Api.cache[tag]) {
105105
Api.cache[tag] = new ProxyDelegateController(tag, _Delegate);
106106
}

src/components/ion-vue-router-transitionless.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<script lang="ts">
88
import { Prop } from 'vue-property-decorator';
99
import Component, { mixins } from 'vue-class-component';
10-
import CatchIonicGoBack from '../mixins/catch-ionic-go-back.js';
10+
import CatchIonicGoBack from '../mixins/catch-ionic-go-back';
1111
1212
@Component
1313
export default class IonVueRouter extends mixins(CatchIonicGoBack) {

src/components/ion-vue-router.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
<script lang="ts">
2727
import { Prop } from 'vue-property-decorator';
2828
import Component, { mixins } from 'vue-class-component';
29-
import CatchIonicGoBack from '../mixins/catch-ionic-go-back.js';
30-
import { IonRouterOutlet } from '../types/interfaces.js';
31-
import Router from '../router.js';
29+
import CatchIonicGoBack from '../mixins/catch-ionic-go-back';
30+
import { IonRouterOutlet } from '../interfaces';
3231
3332
@Component
3433
export default class IonVueRouter extends mixins(CatchIonicGoBack) {
@@ -78,7 +77,7 @@ export default class IonVueRouter extends mixins(CatchIonicGoBack) {
7877
deepWait: true,
7978
duration: this.getDuration(),
8079
direction: this.getDirection(),
81-
showGoBack: (this.$router as Router).canGoBack(),
80+
showGoBack: this.$router.canGoBack(),
8281
});
8382
});
8483
}
@@ -90,7 +89,7 @@ export default class IonVueRouter extends mixins(CatchIonicGoBack) {
9089
9190
// Get the navigation direction from the router
9291
getDirection() {
93-
return (this.$router as Router).direction === 1 ? 'forward' : 'back';
92+
return this.$router.direction === 1 ? 'forward' : 'back';
9493
}
9594
9695
// Set the component to be rendered before we render the new route

src/framework-delegate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { VueConstructor } from 'vue';
2-
import { FrameworkDelegate, HTMLVueElement, WebpackFunction, EsModule } from './types/interfaces';
2+
import { EsModule, FrameworkDelegate, HTMLVueElement, WebpackFunction } from './interfaces';
33

44
export default class Delegate implements FrameworkDelegate {
55
constructor(public vue: VueConstructor) {}

src/types/interfaces.d.ts renamed to src/interfaces.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Vue, { VueConstructor } from 'vue';
2-
import IonicApi from '../api';
1+
import Vue from 'vue';
2+
import IonicApi from './api';
33
import VueRouter from 'vue-router';
44
import { RouterOptions } from 'vue-router/types/router';
55

@@ -9,6 +9,14 @@ declare module 'vue/types/vue' {
99
}
1010
}
1111

12+
declare module 'vue-router/types/router' {
13+
interface VueRouter {
14+
direction: number;
15+
directionOverride: number | null;
16+
canGoBack(): boolean;
17+
}
18+
}
19+
1220
export interface HTMLVueElement extends HTMLElement {
1321
__vue__: Vue;
1422
}
@@ -64,7 +72,7 @@ export interface ProxyControllerInterface {
6472

6573
export interface ProxyDelegateOptions extends Object {
6674
[key: string]: any;
67-
delegate: FrameworkDelegate;
75+
delegate?: FrameworkDelegate;
6876
}
6977

7078
export interface ProxyMenuControllerInterface {

src/mixins/catch-ionic-go-back.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue';
2-
import Router from '../router'
2+
import Router from '../router';
33
import Component from 'vue-class-component';
4-
import { IonBackButton } from '../types/interfaces';
4+
import { IonBackButton } from '../interfaces';
55

66
@Component
77
export default class CatchIonicGoBack extends Vue {
@@ -33,4 +33,4 @@ export default class CatchIonicGoBack extends Vue {
3333
$router.push(defaultHref);
3434
}
3535
}
36-
};
36+
}

src/proxy-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as apiUtils from './api-utils';
2-
import { ProxyControllerInterface } from './types/interfaces';
2+
import { ProxyControllerInterface } from './interfaces';
33

44
// A proxy class that allows early access to controller methods
55
export default class ProxyController implements ProxyControllerInterface {

src/proxy-delegate-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ProxyController from './proxy-controller';
2-
import { FrameworkDelegate, ProxyDelegateOptions } from './types/interfaces';
2+
import { FrameworkDelegate, ProxyDelegateOptions } from './interfaces';
33

44
// A proxy class that allows early access to controller methods
55
export default class ProxyDelegateController extends ProxyController {

src/proxy-menu-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as apiUtils from './api-utils';
2-
import { ProxyMenuControllerInterface } from './types/interfaces';
2+
import { ProxyMenuControllerInterface } from './interfaces';
33

44
// A proxy class that allows early access to controller methods
55
export default class ProxyMenuController implements ProxyMenuControllerInterface {

src/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import VueRouter, { Route } from 'vue-router';
22
import { PluginFunction } from 'vue';
3-
import { RouterArgs, VueWindow } from './types/interfaces';
3+
import { RouterArgs, VueWindow } from './interfaces';
44
import IonVueRouter from './components/ion-vue-router.vue';
55
import IonVueRouterTransitionless from './components/ion-vue-router-transitionless.vue';
66

tsconfig.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"allowSyntheticDefaultImports": true,
66
"allowUnreachableCode": false,
77
"declaration": true,
8+
"declarationMap": true,
9+
"declarationDir": "types",
810
"experimentalDecorators": true,
911
"forceConsistentCasingInFileNames": true,
1012
"jsx": "react",
@@ -26,8 +28,10 @@
2628
"strictPropertyInitialization": false,
2729
"target": "es5"
2830
},
29-
"files": [
30-
"src/index.ts",
31-
"src/sfc.d.ts"
31+
"include": [
32+
"src/**/*.ts"
33+
],
34+
"exclude": [
35+
"node_modules"
3236
]
3337
}

types/api-utils.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { HTMLStencilElement } from './interfaces';
2+
export declare function proxyMethod(tag: string, method: string, ...opts: any[]): Promise<any>;
3+
export declare function initController(tag: string): Promise<HTMLStencilElement>;
4+
//# sourceMappingURL=api-utils.d.ts.map

types/api.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { PluginFunction } from 'vue';
2+
import { ApiCache } from './interfaces';
3+
import ProxyController from './proxy-controller';
4+
import ProxyMenuController from './proxy-menu-controller';
5+
import ProxyDelegateController from './proxy-delegate-controller';
6+
export default class Api {
7+
static cache: ApiCache;
8+
static installed: boolean;
9+
static install: PluginFunction<never>;
10+
readonly actionSheetController: ProxyController;
11+
readonly alertController: ProxyController;
12+
readonly loadingController: ProxyController;
13+
readonly menuController: ProxyMenuController;
14+
readonly modalController: ProxyDelegateController;
15+
readonly popoverController: ProxyDelegateController;
16+
readonly toastController: ProxyController;
17+
}
18+
//# sourceMappingURL=api.d.ts.map
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import CatchIonicGoBack from '../mixins/catch-ionic-go-back';
2+
declare const IonVueRouter_base: import("vue-class-component/lib/declarations").VueClass<CatchIonicGoBack>;
3+
export default class IonVueRouter extends IonVueRouter_base {
4+
name: string;
5+
}
6+
export {};
7+
//# sourceMappingURL=ion-vue-router-transitionless.vue?rollup-plugin-vue=script.d.ts.map
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import CatchIonicGoBack from '../mixins/catch-ionic-go-back';
2+
declare const IonVueRouter_base: import("vue-class-component/lib/declarations").VueClass<CatchIonicGoBack>;
3+
export default class IonVueRouter extends IonVueRouter_base {
4+
name: string;
5+
bindCSS: boolean;
6+
animated: boolean;
7+
leavingEl: HTMLElement;
8+
enteringEl: HTMLElement;
9+
inTransition: boolean;
10+
customTransition: boolean;
11+
created(): void;
12+
transition(enteringEl: HTMLElement, leavingEl: HTMLElement): Promise<boolean> | undefined;
13+
getDuration(): 0 | undefined;
14+
getDirection(): "forward" | "back";
15+
beforeEnter(el: HTMLElement): void;
16+
beforeLeave(el: HTMLElement): void;
17+
leave(el: HTMLElement, done: (opts?: boolean) => void): void;
18+
enter(_el: HTMLElement, done: () => void): void;
19+
afterEnter(): void;
20+
enterCancelled(): void;
21+
afterLeave(): void;
22+
leaveCancelled(): void;
23+
}
24+
export {};
25+
//# sourceMappingURL=ion-vue-router.vue?rollup-plugin-vue=script.d.ts.map

types/framework-delegate.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { VueConstructor } from 'vue';
2+
import { FrameworkDelegate, HTMLVueElement, WebpackFunction } from './interfaces';
3+
export default class Delegate implements FrameworkDelegate {
4+
vue: VueConstructor;
5+
constructor(vue: VueConstructor);
6+
attachViewToDom(parentElement: HTMLElement, component: HTMLElement | WebpackFunction | object | VueConstructor, opts?: object, classes?: string[]): Promise<HTMLElement>;
7+
removeViewFromDom(_parentElement: HTMLElement, childElement: HTMLVueElement): Promise<void>;
8+
vueController(component: WebpackFunction | object | VueConstructor): Promise<VueConstructor>;
9+
vueComponent(controller: VueConstructor, opts?: object): import("vue/types/vue").CombinedVueInstance<import("vue/types/vue").Vue, object, object, object, Record<never, any>>;
10+
}
11+
//# sourceMappingURL=framework-delegate.d.ts.map

types/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { default as Ionic } from './ionic';
2+
export { default as IonicAPI } from './api';
3+
export { default as IonicVueRouter } from './router';
4+
//# sourceMappingURL=index.d.ts.map

0 commit comments

Comments
 (0)