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

Nick/basic types #4

Merged
merged 3 commits into from
Jun 21, 2021
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
### Unknown, never and Tuple
### UtilityTypes
[Pull request](https://github.com/nickovchinnikov/minesweeper/pull/3)

### Minesweeper basic types
[Pull request](https://github.com/nickovchinnikov/minesweeper/pull/4)
22 changes: 11 additions & 11 deletions examples/Types/examples.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
type UserPermissions = 'admin' | 'user' | 'manager';
export type UserPermissions = 'admin' | 'user' | 'manager';

type PermissionsWithoutAdmin = Exclude<UserPermissions, 'admin'>;
export type PermissionsWithoutAdmin = Exclude<UserPermissions, 'admin'>;

interface DepartmentsForPermission {
depName: string;
lvl: number;
}

const DepsForPerms: Record<UserPermissions, DepartmentsForPermission> = {
export const DepsForPerms: Record<UserPermissions, DepartmentsForPermission> = {
admin: {
depName: 'security',
lvl: 10,
Expand All @@ -32,19 +32,19 @@ type BasicUser<A = boolean, P = TuplePermissinons> = {
permissions?: P;
};

type BasicUserWithoutPermissions = Omit<BasicUser, 'permissions'>;
export type BasicUserWithoutPermissions = Omit<BasicUser, 'permissions'>;

type AdvancedUser = {
account: number;
};

type FullUser<A = boolean, P = string[]> = BasicUser<A, P> & AdvancedUser;

type BasicUserReadonly = Readonly<BasicUser>;
type BasicUserRequired = Required<BasicUser>;
type BasicUserPartial = Partial<BasicUser>;
export type BasicUserReadonly = Readonly<BasicUser>;
export type BasicUserRequired = Required<BasicUser>;
export type BasicUserPartial = Partial<BasicUser>;

type BasicUserReadonlyRequired = Readonly<Required<BasicUser>>;
export type BasicUserReadonlyRequired = Readonly<Required<BasicUser>>;

const user: FullUser<boolean> = {
name: 'Nick',
Expand All @@ -65,12 +65,12 @@ function getFirst<T>(arr: T[]): T {

type BasicFunction = () => FullUser[];

type getFirstReturnType = ReturnType<BasicFunction>;
export type getFirstReturnType = ReturnType<BasicFunction>;

getFirst<FullUser>(usersArray);

type MathFunc<T = number> = (a: T, b: T) => T;

const mul: MathFunc = (a, b) => a * b;
export const mul: MathFunc = (a, b) => a * b;

const add: MathFunc = (a, b) => a + b;
export const add: MathFunc = (a, b) => a + b;
11 changes: 11 additions & 0 deletions src/helpers/Field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type Cell = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
export type Field = Cell[][];
export type Coords = [number, number];

export const CellState: Record<string, Cell> = {
empty: 0,
bomb: 9,
hidden: 10,
mark: 11,
weakMark: 12,
};