Skip to content

Commit

Permalink
Merge pull request #518 from soramitsu/512-stricter-type-script
Browse files Browse the repository at this point in the history
[refactor] #512: use stricter tsconfig
  • Loading branch information
0x009922 authored Mar 21, 2023
2 parents 6659284 + db29837 commit cb972c3
Show file tree
Hide file tree
Showing 96 changed files with 477 additions and 378 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-badgers-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@soramitsu-ui/ui': patch
---

**refactor**: refactor internals with stricter TypeScript options
5 changes: 5 additions & 0 deletions .changeset/spotty-jeans-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@soramitsu-ui/ui': minor
---

**refactor**(`SSelect`): use `readonly options` in `UseSelectModelParams`
5 changes: 5 additions & 0 deletions .changeset/thick-rice-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@soramitsu-ui/ui': minor
---

**refactor**(`STableColumn`): use strict type for `sort-orders` prop -- it should be 1-3 length array without duplications
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"test:ui:unit": "pnpm --filter ui test:unit",
"test:ui:cy": "pnpm --filter ui cy:ci:component",
"test:ui:after-build": "pnpm --filter ui test:after-build",
"typecheck": "run-s typecheck:root typecheck:ui",
"typecheck:root": "tsc --noEmit",
"typecheck:ui": "pnpm --filter ui typecheck",
"build": "run-s build:vite-plugin-svg build:ui",
"build:vite-plugin-svg": "pnpm --filter vite-plugin-svg build",
"build:ui": "pnpm --filter ui build",
Expand All @@ -29,10 +32,10 @@
"devDependencies": {
"@changesets/cli": "^2.17.0",
"@types/node": "^18.14.6",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"del-cli": "^5.0.0",
"eslint": "^8.16.0",
"eslint": "^8.36.0",
"eslint-config-alloy": "^4.5.1",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-vue": "^9.0.1",
Expand All @@ -41,7 +44,8 @@
"prettier": "^2.6.2",
"prettier-eslint": "^15.0.0",
"prettier-eslint-cli": "^7.1.0",
"typescript": "5.0.1-rc",
"typescript": "5.0.2",
"vite": "^4.1.4",
"vitest": "^0.29.2"
}
}
2 changes: 1 addition & 1 deletion packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"src"
],
"scripts": {
"test": "vitest"
"test": "vitest run"
},
"devDependencies": {
"sass": "^1.49.0"
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/cypress/component/SModal.spec.cy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { VueTestUtils } from 'cypress/vue'
import { Ref } from 'vue'
import type { Ref } from 'vue'
import { bareMetalVModel } from '@/util'
import { SModal, SModalCard, useModalApi, SBodyScrollLockProvider, BodyScrollLockApi } from '@/lib'
import { SModal, SModalCard, useModalApi, SBodyScrollLockProvider, type BodyScrollLockApi } from '@/lib'
import { objectPick } from '@vueuse/core'
import { Options as FocusTrapOptions } from 'focus-trap'
import { type Options as FocusTrapOptions } from 'focus-trap'
import { enableBodyScroll, disableBodyScroll } from 'body-scroll-lock'

const showVModel = (val: Ref<boolean>) => bareMetalVModel(val, 'show')
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/cypress/component/SPopover.spec.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SPopover, SPopoverWrappedTransition } from '@/components/Popover'
import { usePopoverApi } from '@/components/Popover/api'

import { Instance } from '@popperjs/core'
import { type Instance } from '@popperjs/core'
import { VueTestUtils } from 'cypress/vue'

before(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/cypress/component/STabsPanel.spec.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VueTestUtils } from 'cypress/vue'
import { STabsPanel, STab, useTabsPanelApi, TabsPanelApi } from '@/lib'
import { STabsPanel, STab, useTabsPanelApi, type TabsPanelApi } from '@/lib'

before(() => {
VueTestUtils.config.global.components = { STabsPanel, STab }
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/cypress/component/SToasts.spec.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SToastsProvider, SToastsDisplay, ToastsApi, TOASTS_API_KEY } from '@/lib'
import { SToastsProvider, SToastsDisplay, type ToastsApi, TOASTS_API_KEY } from '@/lib'

import { VueTestUtils } from 'cypress/vue'
import { forceInject } from '@/util'
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"types": ["cypress", "cypress-axe"],
"paths": {
"@/*": ["../src/*"]
}
},
"noEmit": true
},
"include": ["./", "../auto-imports.d.ts", "../src"]
}
5 changes: 3 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
"cy": "cypress open",
"cy:ci:component": "cypress run --component --quiet --reporter spec",
"typecheck": "vue-tsc --noEmit",
"typecheck:cypress": "vue-tsc -p ./cypress",
"build": "run-s build:clean build:vite build:dts",
"build:clean": "del dist ts-build",
"build:vite": "vite build",
"build:dts": "run-s build:dts:tsc build:dts:rollup",
"build:dts:tsc": "vue-tsc --outDir ts-build --declaration --emitDeclarationOnly",
"build:dts:tsc": "vue-tsc -p tsconfig.build.json",
"build:dts:rollup": "rollup -c rollup.dts.config.cjs"
},
"dependencies": {
Expand Down Expand Up @@ -82,7 +83,7 @@
"storybook": "^7.0.0-beta.62",
"tabbable": "^6.0.0",
"ts-pattern": "^4.2.1",
"typescript": "5.0.1-rc",
"typescript": "5.0.2",
"unimport": "^3.0.2",
"unplugin-auto-import": "^0.15.1",
"unplugin-icons": "^0.15.3",
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/rollup.dts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const shimCssPlugin = (): Plugin => {
name: 'soramitsu-ui:shim-css',
resolveId(id) {
if (/\.(css|scss|sass)$/.test(id)) return id + CSS_SUFFIX
return
},
load(id) {
if (id.endsWith(CSS_SUFFIX)) return `declare const css: string\n export default css`
return
},
}
}
Expand All @@ -27,7 +29,7 @@ export default defineConfig({
},
}),
shimCssPlugin(),
dtsPlugin(),
dtsPlugin() as Plugin,
],
onwarn(warning, defaultHandler) {
match(warning)
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/Accordion/SAccordion.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { AccordionItemApi, AccordionApi, ACCORDION_API_KEY } from './api'
import { provide, Ref, watch } from 'vue'
import { type AccordionItemApi, type AccordionApi, ACCORDION_API_KEY } from './api'
import { provide, type Ref, watch } from 'vue'
const props = withDefaults(
defineProps<{
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/Accordion/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InjectionKey, Ref, inject } from 'vue'
import { type InjectionKey, type Ref, inject } from 'vue'

export interface AccordionItemApi {
name: string
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/Badge/SBadge.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { SSpinner } from '../Spinner'
import { BadgeType } from './api'
import { type BadgeType } from './api'
const props = withDefaults(
defineProps<{
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/BodyScrollLockProvider/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MaybeElementRef } from '@vueuse/core'
import type { MaybeElementRef } from '@vueuse/core'
import type { VNode, InjectionKey, PropType } from 'vue'

export interface BodyScrollLockApi {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/Button/SButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SPINNER_WIDTH,
FONT_SIZE,
} from './consts'
import { ButtonType, ButtonSize, ButtonIconPosition, HTMLButtonType } from './types'
import type { ButtonType, ButtonSize, ButtonIconPosition, HTMLButtonType } from './types'
const props = withDefaults(
defineProps<{
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/Checkbox/SCheckboxAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import './SCheckboxAtom.scss'
import IconCheck from '~icons/uil/check'
import IconMinus from '~icons/uil/minus'

import { FunctionalComponent, mergeProps, PropType } from 'vue'
import { CheckboxSize, CheckboxState } from './types'
import { type FunctionalComponent, mergeProps, type PropType } from 'vue'
import type { CheckboxSize, CheckboxState } from './types'

interface Props {
size: CheckboxSize
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/Checkbox/SCheckboxSolo.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { uniqueElementId } from '@/util'
import { CheckboxSize, CheckboxType, CHECKBOX_SIZE_VALUES, CHECKBOX_TYPE_VALUES } from './types'
import { type CheckboxSize, type CheckboxType, CHECKBOX_SIZE_VALUES, CHECKBOX_TYPE_VALUES } from './types'
import { usePropTypeFilter } from '@/composables/prop-type-filter'
import SRadioBody from '../Radio/SRadioBody'
import SCheckboxAtom from './SCheckboxAtom'
Expand Down
18 changes: 8 additions & 10 deletions packages/ui/src/components/DatePicker/SDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SPopover, SPopoverWrappedTransition } from '@/components/Popover'
import { and } from '@vueuse/math'
import { format } from 'date-fns'
import {
import type {
DatePickerType,
RangeState,
DateState,
Expand All @@ -20,7 +20,7 @@ import {
ModelValueType,
DatePickerOptions,
} from './types'
import { DatePickerApi, DATE_PICKER_API_KEY } from './api'
import { type DatePickerApi, DATE_PICKER_API_KEY } from './api'
import { DEFAULT_SHORTCUTS } from './consts'
type Props = {
Expand Down Expand Up @@ -78,8 +78,8 @@ const init = () => {
} else if (props.type === 'pick') {
pickState.value = innerModelValue.value as PickState
} else {
rangeStateRef.value.startDate = (innerModelValue.value as Date[])[0]
rangeStateRef.value.endDate = (innerModelValue.value as Date[])[1]
rangeStateRef.value.startDate = (innerModelValue.value as Date[])[0]!
rangeStateRef.value.endDate = (innerModelValue.value as Date[])[1]!
}
updateShowedMonths()
}
Expand Down Expand Up @@ -125,17 +125,16 @@ const updateShowedMonths = () => {
let date: Date | null = null
switch (props.type) {
case 'pick':
date = pickState.value[pickState.value.length - 1]
date = pickState.value[pickState.value.length - 1]!
break
case 'day':
date = dayState.value
break
case 'range':
date = rangeState[dateForTime.value as keyof RangeState] as Date | null
break
default:
}
if (!date) return `00:00`
if (!date) return
updateShowedState(date.getMonth(), date.getFullYear())
}
Expand Down Expand Up @@ -196,7 +195,7 @@ const changeView = (viewName: string) => {
currentView.value = viewName
}
const headTitle = computed(() => {
const headTitle = computed<string>(() => {
if (menuState.value && menuState.value !== 'Custom') {
return menuState.value
}
Expand All @@ -209,13 +208,12 @@ const headTitle = computed(() => {
const modelValue = props.modelValue as Date[]
return modelValue.map((item) => formatDate(item)).join(' - ')
}
case 'pick': {
const modelValue = props.modelValue as Date[]
return modelValue.map((item) => formatDate(item)).join(', ')
}
default:
break
return ''
}
} catch {
return ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import MonthTable from './SDatePickerTableMonths.vue'
import YearTable from './SDatePickerTableYears.vue'
import DatePanel from './SDatePickerPanelDate.vue'
import { StateStore, ShowState, ModelValueType } from './types'
import { DatePickerApi, useDatePickerApi } from './api'
import type { StateStore, ShowState, ModelValueType } from './types'
import { type DatePickerApi, useDatePickerApi } from './api'
type Props = {
currentView: string
Expand All @@ -29,7 +29,7 @@ const firstCalendarModelValue = computed(() => {
if (!props.modelValue) return new Date()
if (state.type === 'range') {
const modelValue = props.modelValue as Date[]
const modelValue = props.modelValue as [Date, ...Date[]]
return modelValue[0]
} else {
return props.modelValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { RangeState, StateStore } from './types'
import type { RangeState, StateStore } from './types'
import { parse, isValid } from 'date-fns'
import { DatePickerApi, useDatePickerApi } from './api'
import { type DatePickerApi, useDatePickerApi } from './api'
type Props = {
stateStore: StateStore
Expand Down Expand Up @@ -92,6 +92,8 @@ function dateMask(date: string) {
if (date.match(/^\d{2}\/\d{2}$/) !== null) {
return date + '/'
}
return undefined
}
function dateTimeMask(date: string) {
Expand All @@ -112,6 +114,8 @@ function dateTimeMask(date: string) {
if (date.match(/^\d{2}\/\d{2}\/\d{4}, \d{2}:\d{2}$/) !== null) {
return date
}
return undefined
}
const customInputLength = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import MonthPanel from './SDatePickerPanelMonths.vue'
import DateTable from './SDatePickerTableDate.vue'
import { ShowState, StateStore } from './types'
import type { ShowState, StateStore } from './types'
type Props = {
showState: ShowState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { IconArrowsChevronRight24, IconArrowsChevronLeft24 } from '@/components/icons'
import { months } from './consts'
import { ShowState } from './types'
import type { ShowState } from './types'
type Props = {
showState: ShowState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { DatePickerOptions } from './types'
import type { DatePickerOptions } from './types'
import { IconBasicCheckMark24 } from '@/components/icons'
import { DatePickerApi, useDatePickerApi } from './api'
import { type DatePickerApi, useDatePickerApi } from './api'
type Props = {
menuState: string
Expand Down
Loading

0 comments on commit cb972c3

Please sign in to comment.