Skip to content

Commit

Permalink
feat: add Nullable type
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanwww committed Aug 6, 2023
1 parent 99283ca commit bb98260
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/app-common/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './function';
export * from './utils';
1 change: 1 addition & 0 deletions packages/app-common/src/types/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Nullable<T> = T | null;
2 changes: 1 addition & 1 deletion packages/app-common/src/utils/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function assert(value: unknown): asserts value {
}

/**
* The function for asserting whether a value's type is `never` at compile time.
* The function for asserting whether a value's type is `never`.
*/
export function assertIsNever(value: never): never {
throw new Error(`Assertion Error: ${String(value)} should be "never" type.`);
Expand Down
3 changes: 2 additions & 1 deletion packages/app-main/src/main/window/windowManager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Nullable } from '@ter/app-common';
import { WindowType, assertIsNever } from '@ter/app-common';

import type { AbstractWindow } from './abstractWindow';
import { MainWindow } from './mainWindow';
import type { CloseWindowOption, CreateWindowOption } from './types';

interface WindowStore {
[id: string]: AbstractWindow | null;
[id: string]: Nullable<AbstractWindow>;
}

export class WindowManager {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { AppDetails } from '@ter/app-common';
import type { AppDetails, Nullable } from '@ter/app-common';

import { Assets } from 'src/assets';

import css from './Introduction.module.scss';

interface IntroductionProps {
appDetails: AppDetails | null;
appDetails: Nullable<AppDetails>;
}

export function Introduction({ appDetails }: IntroductionProps): JSX.Element {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-renderer/src/MainWindow/redux/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { AppDetails } from '@ter/app-common';
import type { AppDetails, Nullable } from '@ter/app-common';

import type { ReduxReducer } from 'src/utils/redux';

export interface StoreState {
appDetails: AppDetails | null;
appDetails: Nullable<AppDetails>;
}

export type MainReducer<Payload = undefined> = ReduxReducer<StoreState, Payload>;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Nullable } from '@ter/app-common';
import { assert } from '@ter/app-common';
import { act, render } from '@testing-library/react';
import { noop } from 'lodash';
Expand All @@ -11,8 +12,8 @@ describe(`Test react hook \`${usePersistFn.name}\``, () => {
validateHookValueNotChanged('should return the same callbacks', () => [usePersistFn(noop)]);

it('should call the latest non-persist function', () => {
let count: number | null = null;
let increaseCount = null as (() => void) | null;
let count: Nullable<number> = null;
let increaseCount = null as Nullable<() => void>;
expect(count).toBeNull();
expect(increaseCount).toBeNull();

Expand Down

0 comments on commit bb98260

Please sign in to comment.