Skip to content

Commit 2e97b33

Browse files
committed
string typescript is on
1 parent 6536264 commit 2e97b33

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

src/components/Calculator.js src/components/Calculator.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ import { getSalaryInfo, formatCurrency } from "./utils";
55
import "./Calculator.css";
66

77
const Calculator = () => {
8-
const [salary, setSalary] = useState(70000);
8+
const [salary, setSalary] = useState<string>("70000");
99

10-
const handleChangeSalary = (event) => {
11-
setSalary(event.target.value);
10+
const handleChangeSalary = (event: InputEvent) => {
11+
if (event.target instanceof HTMLInputElement) {
12+
setSalary(event.target.value);
13+
}
1214
};
1315

14-
const { nettoSalary, pension, tax, grossSalary, insurance } =
15-
getSalaryInfo(salary);
16+
const { nettoSalary, pension, tax, grossSalary, insurance } = getSalaryInfo(
17+
Number(salary),
18+
);
1619

1720
return (
1821
<div className="Calculator">

src/components/utils.js src/components/utils.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@ const currencyFormatter = new Intl.NumberFormat("ru-KZ", {
33
currency: "KZT",
44
});
55

6-
export const getPension = (nettoSalary, minSalary) =>
6+
export const getPension = (nettoSalary: number, minSalary: number) =>
77
nettoSalary * 0.1 < minSalary * 75 ? nettoSalary * 0.1 : minSalary * 75;
88

9-
export const getTax = (nettoSalary, minSalary, pension) =>
9+
export const getTax = (
10+
nettoSalary: number,
11+
minSalary: number,
12+
pension: number,
13+
) =>
1014
nettoSalary === minSalary ? 0 : (nettoSalary - pension - minSalary) * 0.1;
1115

12-
export const getGrossSalary = (nettoSalary, pension, tax) =>
13-
nettoSalary - pension - tax;
16+
export const getGrossSalary = (
17+
nettoSalary: number,
18+
pension: number,
19+
tax: number,
20+
) => nettoSalary - pension - tax;
1421

15-
export const getInsurance = (salary) => salary * 0.01;
22+
export const getInsurance = (salary: number) => salary * 0.01;
1623

17-
export const getSalaryInfo = (salary) => {
24+
// TODO: fix calculation and cover with tests
25+
export const getSalaryInfo = (salary: number) => {
1826
const minSalary = 70000;
1927
if (salary <= minSalary) {
2028
return { nettoSalary: salary, pension: 0, tax: 0, grossSalary: salary };
@@ -29,4 +37,4 @@ export const getSalaryInfo = (salary) => {
2937
return { nettoSalary, pension, tax, grossSalary, insurance };
3038
};
3139

32-
export const formatCurrency = (number) => currencyFormatter.format(number);
40+
export const formatCurrency = (num: number) => currencyFormatter.format(num);

src/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export function App() {
77
return <Calculator />;
88
}
99

10-
render(<App />, document.getElementById("app"));
10+
render(<App />, document.getElementById("app")!);

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"allowJs": true,
88
"checkJs": true,
99
"jsx": "react-jsx",
10+
"strict": true,
1011
"jsxImportSource": "preact"
1112
},
1213
"include": ["node_modules/vite/client.d.ts", "**/*"]

0 commit comments

Comments
 (0)