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

Strict null checks loosely #7011

Merged
merged 4 commits into from
Jan 23, 2025
Merged
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
32 changes: 32 additions & 0 deletions ignored-error-codes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
"TS18046",
"TS18047",
"TS18048",
"TS18049",
"TS2322",
"TS2339",
"TS2344",
"TS2345",
"TS2349",
"TS2352",
"TS2366",
"TS2367",
"TS2416",
"TS2418",
"TS2454",
"TS2464",
"TS2488",
"TS2531",
"TS2532",
"TS2537",
"TS2538",
"TS2578",
"TS2604",
"TS2719",
"TS2722",
"TS2769",
"TS2783",
"TS2786",
"TS2790",
"TS2845"
]
540 changes: 540 additions & 0 deletions loosely-type-checked-files.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"test:watch:all": "vitest --watchAll",
"test:coverage": "vitest --coverage --selectProjects test",
"test-storybook": "test-storybook --url http://127.0.0.1:9001 --testTimeout=30_000",
"ts-check": "tsc --pretty && tsc --pretty --project packages/v2/tsconfig.json",
"ts-check": "tsc | loose-ts-check && tsc --pretty --project packages/v2/tsconfig.json",
"ts-check:update-ignored": "tsc | loose-ts-check --auto-update && tsc --pretty --project packages/v2/tsconfig.json",
"ts-check:v2": "tsc --pretty --project packages/v2/tsconfig.json",
"lint": "eslint --cache packages",
"lint:fix": "eslint --fix --cache packages --ext .ts,.tsx,.js,.jsx",
"css:lint": "stylelint \"packages/**/*.css\"",
Expand Down Expand Up @@ -101,6 +103,7 @@
"husky": "9.1.7",
"jsdom": "25.0.1",
"lint-staged": "15.4.1",
"loose-ts-check": "^2.0.0",
"msw": "2.7.0",
"msw-storybook-addon": "^2.0.4",
"postcss": "^8.5.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/form/src/DecimalField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface DecimalFieldProps {

const createNormalizeOnBlurField = WrappedNavFieldComponent => {
interface FieldComponentProps {
normalizeOnBlur: (value: any) => void;
normalizeOnBlur?: (value: any) => void;
component?: () => reduxFormField;
}
class FieldComponent extends Component<FieldComponentProps & WrappedComponentProps> {
Expand All @@ -41,7 +41,6 @@ const createNormalizeOnBlurField = WrappedNavFieldComponent => {
// @ts-expect-error Migrert frå ts-ignore, uvisst kvifor denne trengs
<Comp
{...props}
// @ts-expect-error Migrert frå ts-ignore, uvisst kvifor denne trengs
input={{
...input,
onBlur: event => {
Expand Down
11 changes: 7 additions & 4 deletions packages/utils/src/arrayUtils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
export const range = (length: number) => [...Array(length).keys()];

const isObject = (v: unknown): v is object => typeof v === 'object';

export const haystack = (object: unknown, keys: string | string[], defaultValue = null) => {
const keysArray = Array.isArray(keys) ? keys : keys.replace(/(\[(\d+)\])/g, '.$2').split('.');
const currentObject = object[keysArray[0]];
const keysArray: string[] = Array.isArray(keys) ? keys : keys.replace(/(\[(\d+)\])/g, '.$2').split('.');
const firstKey = keysArray[0];
const currentObject = isObject(object) ? object[firstKey] : undefined;
if (currentObject && keysArray.length > 1) {
return haystack(currentObject, keysArray.slice(1), defaultValue);
}
return currentObject === undefined ? defaultValue : currentObject;
};

export const makeArrayWithoutDuplicates = (array: unknown[]) => {
const arrayWithoutDuplicates = [];
export const makeArrayWithoutDuplicates = <T>(array: T[]): T[] => {
const arrayWithoutDuplicates: T[] = [];
array.forEach(value => {
if (!arrayWithoutDuplicates.includes(value)) {
arrayWithoutDuplicates.push(value);
Expand Down
4 changes: 1 addition & 3 deletions packages/v2/lib/src/dateUtils/dateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,12 @@ export const convertHoursToDays = (hoursToConvert: number) => {
};

export const splitWeeksAndDays = (weeks: number, days: number) => {
const returnArray = [];
const allDays = weeks ? weeks * 5 + days : days;
const firstPeriodDays = allDays % 2 === 0 ? allDays / 2 : allDays / 2 + 0.5;
const secondPeriodDays = allDays % 2 === 0 ? allDays / 2 : allDays / 2 - 0.5;
const firstPeriodWeeksAndDays = { weeks: Math.trunc(firstPeriodDays / 5), days: firstPeriodDays % 5 };
const secondPeriodWeeksAndDays = { weeks: Math.trunc(secondPeriodDays / 5), days: secondPeriodDays % 5 };
returnArray.push(secondPeriodWeeksAndDays, firstPeriodWeeksAndDays);
return returnArray;
return [secondPeriodWeeksAndDays, firstPeriodWeeksAndDays];
};

export const formatDate = (date: string) => initializeDate(date).format(DDMMYYYY_DATE_FORMAT);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"allowJs": true,
"noEmit": true,
"strict": false,
"strictNullChecks": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"sourceMap": true,
Expand Down
28 changes: 26 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13438,6 +13438,7 @@ __metadata:
i18n-iso-countries: 7.13.0
jsdom: 25.0.1
lint-staged: 15.4.1
loose-ts-check: ^2.0.0
msw: 2.7.0
msw-storybook-addon: ^2.0.4
node-cache: 5.1.2
Expand Down Expand Up @@ -13701,6 +13702,20 @@ __metadata:
languageName: node
linkType: hard

"loose-ts-check@npm:^2.0.0":
version: 2.0.0
resolution: "loose-ts-check@npm:2.0.0"
dependencies:
chalk: ^4.1.0
minimatch: ^5.1.2
ts-invariant: ^0.10.3
yargs: ^17.6.2
bin:
loose-ts-check: bin/loose-ts-check
checksum: 1db97ef79d41b081fb5d7d03ae52a4ed152e3b330c7a47b9deb44a5309d3758cc72d1d1ee2af824c18f24bf64a3526dd4d54aaaf5e75796ecbd957e991528d9d
languageName: node
linkType: hard

"loupe@npm:^3.1.0, loupe@npm:^3.1.1":
version: 3.1.1
resolution: "loupe@npm:3.1.1"
Expand Down Expand Up @@ -14002,7 +14017,7 @@ __metadata:
languageName: node
linkType: hard

"minimatch@npm:^5.0.1":
"minimatch@npm:^5.0.1, minimatch@npm:^5.1.2":
version: 5.1.6
resolution: "minimatch@npm:5.1.6"
dependencies:
Expand Down Expand Up @@ -17697,6 +17712,15 @@ __metadata:
languageName: node
linkType: hard

"ts-invariant@npm:^0.10.3":
version: 0.10.3
resolution: "ts-invariant@npm:0.10.3"
dependencies:
tslib: ^2.1.0
checksum: bb07d56fe4aae69d8860e0301dfdee2d375281159054bc24bf1e49e513fb0835bf7f70a11351344d213a79199c5e695f37ebbf5a447188a377ce0cd81d91ddb5
languageName: node
linkType: hard

"tsconfig-paths@npm:^4.2.0":
version: 4.2.0
resolution: "tsconfig-paths@npm:4.2.0"
Expand Down Expand Up @@ -18948,7 +18972,7 @@ __metadata:
languageName: node
linkType: hard

"yargs@npm:^17.3.1, yargs@npm:^17.7.2":
"yargs@npm:^17.3.1, yargs@npm:^17.6.2, yargs@npm:^17.7.2":
version: 17.7.2
resolution: "yargs@npm:17.7.2"
dependencies:
Expand Down
Loading