Skip to content

Commit

Permalink
Update tsconfig paths and add vue-shim.d.ts
Browse files Browse the repository at this point in the history
Update paths in `shell/tsconfig.paths.json` to include "@components/*" alias that maps to "../pkg/rancher-components/src/components/*". Typescript was unable to properly locate components using the `@components` alias because this path was not defined.

Add declarations to support our i18n plugin to `shell/types/vue-shim.d.ts` so that `this.t()` and the `t` component can be recognized in components utilizing `defineComponent`.

Signed-off-by: Phillip Rak <[email protected]>
  • Loading branch information
rak-phillip committed Jan 10, 2024
1 parent 610b826 commit 455fd39
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
5 changes: 4 additions & 1 deletion shell/tsconfig.paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
],
"@pkg/*": [
"../shell/pkg/*"
],
"@components/*": [
"../pkg/rancher-components/src/components/*"
]
},
},
}
}
42 changes: 42 additions & 0 deletions shell/types/vue-shim.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// eslint-disable-next-line no-unused-vars
import Vue, { ComponentCustomProperties } from 'vue';
declare module '*.vue' {
export default Vue;
}

// This is required to keep typescript from complaining. It is required for
// our i18n plugin. For more info see:
// https://v2.vuejs.org/v2/guide/typescript.html?redirect=true#Augmenting-Types-for-Use-with-Plugins
declare module 'vue/types/vue' {
// eslint-disable-next-line no-unused-vars
interface Vue {
/**
* Lookup a given string with the given arguments
* @param raw if set, do not do HTML escaping.
*/
t: {
(key: string, args?: Record<string, any>, raw?: boolean): string;
(options: { k: string; raw?: boolean; tag?: string | Record<string, any>; escapehtml?: boolean }): string;
};
}
}

declare module '@vue/runtime-core' {
// eslint-disable-next-line no-unused-vars
interface Vue {
t: {
(key: string, args?: Record<string, any>, raw?: boolean): string;
(options: { k: string; raw?: boolean; tag?: string | Record<string, any>; escapehtml?: boolean }): string;
}
}

// eslint-disable-next-line no-unused-vars
interface ComponentCustomProperties {
$t: {
(key: string, args?: Record<string, any>, raw?: boolean): string;
(options: { k: string; raw?: boolean; tag?: string | Record<string, any>; escapehtml?: boolean }): string;
}
}
}

declare module 'js-yaml';

0 comments on commit 455fd39

Please sign in to comment.