-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Remove @ts-strict-ignore and fix TypeScript errors [taxes] #6116
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| // @ts-strict-ignore | ||
| import { useExitFormDialog } from "@dashboard/components/Form/useExitFormDialog"; | ||
| import { TaxClassRateInput, TaxCountryConfigurationFragment } from "@dashboard/graphql"; | ||
| import useForm, { SubmitPromise } from "@dashboard/hooks/useForm"; | ||
|
|
@@ -23,21 +22,21 @@ interface TaxCountriesFormProps { | |
|
|
||
| function useTaxCountriesForm( | ||
| country: TaxCountryConfigurationFragment, | ||
| onSubmit, | ||
| disabled, | ||
| onSubmit: (data: TaxClassRateInput[]) => SubmitPromise, | ||
| disabled: boolean, | ||
| ): UseTaxCountriesFormResult { | ||
| // Initial | ||
| const intl = useIntl(); | ||
| const initialFormsetData = country?.taxClassCountryRates.map(item => ({ | ||
| id: item.taxClass?.id ?? null, | ||
| label: item.taxClass?.name ?? intl.formatMessage(taxesMessages.countryDefaultRate), | ||
| value: item.rate?.toString() ?? "", | ||
| data: null, | ||
| data: null as any, | ||
| })); | ||
| const { formId, triggerChange } = useForm({}, undefined, { | ||
| confirmLeave: true, | ||
| }); | ||
| const formset = useFormset(initialFormsetData); | ||
| const formset = useFormset(initialFormsetData as any); | ||
|
||
| // Handlers | ||
| const handleRateChange = (id: string, value: string) => { | ||
| triggerChange(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,3 @@ | ||||||
| // @ts-strict-ignore | ||||||
| import { | ||||||
| CountryCode, | ||||||
| CountryRateInput, | ||||||
|
|
@@ -12,20 +11,21 @@ import { mapMetadataItemToInput } from "@dashboard/utils/maps"; | |||||
| import { TaxClassesPageFormData } from "../types"; | ||||||
|
|
||||||
| export const getTaxClassInitialFormData = (taxClass?: TaxClassFragment): TaxClassesPageFormData => { | ||||||
| const initialCountries = taxClass?.countries | ||||||
| .map(item => ({ | ||||||
| id: item.country.code, | ||||||
| label: item.country.country, | ||||||
| value: item.rate?.toString() ?? "", | ||||||
| data: null, | ||||||
| })) | ||||||
| .sort((a, b) => a.label.localeCompare(b.label)); | ||||||
| const initialCountries = | ||||||
| taxClass?.countries | ||||||
| .map(item => ({ | ||||||
| id: item.country.code, | ||||||
| label: item.country.country, | ||||||
| value: item.rate?.toString() ?? "", | ||||||
| data: null as any, | ||||||
|
||||||
| data: null as any, | |
| data: undefined, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| // @ts-strict-ignore | ||
| import { | ||
| CountryFragment, | ||
| TaxClassFragment, | ||
|
|
@@ -29,7 +28,7 @@ export const mapUndefinedTaxRatesToCountries = ( | |
| ...config.taxClassCountryRates, | ||
| ...taxClasses.map(taxClass => ({ | ||
| taxClass, | ||
| rate: undefined, | ||
| rate: null, | ||
|
||
| __typename: "TaxClassCountryRate" as const, | ||
| })), | ||
| ], | ||
|
|
@@ -39,16 +38,16 @@ export const mapUndefinedTaxRatesToCountries = ( | |
| const parsedCountryRates = taxClassCountryRates.filter(rate => rate.taxClass !== null); | ||
|
|
||
| parsedCountryRates.unshift( | ||
| defaultRate ?? { | ||
| rate: undefined, | ||
| (defaultRate ?? { | ||
| rate: null, | ||
|
||
| taxClass: null, | ||
| __typename: "TaxClassCountryRate" as const, | ||
| }, | ||
| }) as any, | ||
|
||
| ); | ||
|
|
||
| return { | ||
| ...config, | ||
| taxClassCountryRates: parsedCountryRates, | ||
| taxClassCountryRates: parsedCountryRates as typeof config.taxClassCountryRates, | ||
|
||
| }; | ||
| } | ||
| }) | ||
|
|
@@ -65,12 +64,12 @@ export const mapUndefinedCountriesToTaxClasses = ( | |
| ...taxClass.countries, | ||
| ...taxConfigurations.map(({ country }) => ({ | ||
| __typename: "TaxClassCountryRate" as const, | ||
| rate: undefined, | ||
| rate: null, | ||
|
||
| country, | ||
| })), | ||
| ], | ||
| "country.code", | ||
| ), | ||
| ) as typeof taxClass.countries, | ||
|
||
| })); | ||
|
|
||
| export const isLastElement = (arr: any[], index: number): boolean => index === arr.length - 1; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type assertion
data: null as anybypasses type safety. Consider defining a proper type for this field or using the actual expected type instead ofany.