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

Resolve typescript warnings for Rancher Components #11978

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
// @ts-nocheck
import { defineComponent } from 'vue';
import { defineComponent, inject } from 'vue';
import TextAreaAutoGrow from '@components/Form/TextArea/TextAreaAutoGrow.vue';
import LabeledTooltip from '@components/LabeledTooltip/LabeledTooltip.vue';
import { escapeHtml } from '@shell/utils/string';
Expand All @@ -10,12 +9,16 @@ import { debounce } from 'lodash';
import { useLabeledFormElement, labeledFormElementProps } from '@shell/composables/useLabeledFormElement';
import { useCompactInput } from '@shell/composables/useCompactInput';

declare module 'vue/types/vue' {
interface Vue {
onInput: (event: Event) => void | ((event: Event) => void);
}
interface NonReactiveProps {
onInput: (event: Event) => void | ((event: Event) => void);
}

const provideProps: NonReactiveProps = {
onInput() {
// noop
},
};

export default defineComponent({
components: { LabeledTooltip, TextAreaAutoGrow },

Expand Down Expand Up @@ -116,10 +119,13 @@ export default defineComponent({
} = useLabeledFormElement(props, emit);
const { isCompact } = useCompactInput(props);

const onInput = inject('onInput', provideProps.onInput);

return {
focused,
onFocusLabeled,
onBlurLabeled,
onInput,
isDisabled,
validationMessage,
requiredField,
Expand Down Expand Up @@ -175,7 +181,7 @@ export default defineComponent({
return this.t('generic.invalidCron');
}
try {
const hint = cronstrue.toString(this.value);
const hint = cronstrue.toString(this.value.toString());

return hint;
} catch (e) {
Expand Down Expand Up @@ -326,7 +332,7 @@ export default defineComponent({
v-bind="$attrs"
:maxlength="_maxlength"
:disabled="isDisabled"
:value="value"
:value="value.toString()"
:placeholder="_placeholder"
autocapitalize="off"
:class="{ conceal: type === 'multiline-password' }"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
// @ts-nocheck
import { defineComponent } from 'vue';
import { _VIEW } from '@shell/config/query-params';
import { randomStr } from '@shell/utils/string';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<script lang="ts">
// @ts-nocheck
import { defineComponent } from 'vue';
import { defineComponent, inject, PropType } from 'vue';
import debounce from 'lodash/debounce';
import { _EDIT, _VIEW } from '@shell/config/query-params';

declare module 'vue/types/vue' {
/* eslint-disable no-unused-vars */
interface Vue {
queueResize(): void;
}
interface NonReactiveProps {
queueResize(): void;
}

const provideProps: NonReactiveProps = {
queueResize() {
// noop
}
};

export default defineComponent({
inheritAttrs: false,

Expand All @@ -21,7 +23,7 @@ export default defineComponent({
},

class: {
type: String,
type: [String, Array, Object] as PropType<string | unknown[] | Record<string, boolean>>,
default: ''
},

Expand Down Expand Up @@ -78,6 +80,12 @@ export default defineComponent({
}
},

setup() {
const queueResize = inject('queueResize', provideProps.queueResize);

return { queueResize };
},

data() {
return {
curHeight: this.minHeight,
Expand All @@ -101,7 +109,7 @@ export default defineComponent({
return `height: ${ this.curHeight }px; overflow: ${ this.overflow };`;
},

className(): string {
className(): string | unknown[] | Record<string, boolean> {
return this.class;
}
},
Expand Down
21 changes: 6 additions & 15 deletions pkg/rancher-components/src/components/StringList/StringList.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script lang="ts">
// @ts-nocheck
import { PropType, defineComponent } from 'vue';

import LabeledInput from '@components/Form/LabeledInput/LabeledInput.vue';
import { findStringIndex, hasDuplicatedStrings } from '@shell/utils/array';
import LabeledInput from '@components/Form/LabeledInput/LabeledInput.vue';

type Error = 'duplicate';
type ErrorMessages = Record<Error, string>;
Expand Down Expand Up @@ -31,19 +29,15 @@ const CLASS = {
* Manage a list of strings
*/
export default defineComponent({

name: 'StringList',
components: { LabeledInput },

props: {
props: {
/**
* The items source
*/
items: {
type: Array as PropType<string[]>,
default() {
return [];
},
type: Array as PropType<string[]>,
default: () => [],
},
/**
* Determines if items with same text will be treated differently, depending on the letters case
Expand Down Expand Up @@ -78,10 +72,8 @@ export default defineComponent({
* Custom Error messages
*/
errorMessages: {
type: Object as PropType<ErrorMessages>,
default() {
return {} as ErrorMessages;
},
type: Object as PropType<ErrorMessages>,
default: () => ({} as ErrorMessages),
},
/**
* Enables bulk addition and defines the delimiter to split the input string.
Expand Down Expand Up @@ -416,7 +408,6 @@ export default defineComponent({
this.$emit('change', items);
},
},

});
</script>

Expand Down
14 changes: 6 additions & 8 deletions pkg/rancher-components/src/shim-vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Vue from 'vue';
declare module '*.vue' {
import { DefineComponent } from 'vue'

export default Vue;
declare module '*.vue' {
const component: DefineComponent<{}, {}, any>
export default component
}

// 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' {
interface Vue {
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
/**
* Lookup a given string with the given arguments
* @param raw if set, do not do HTML escaping.
Expand Down
Loading