Skip to content

Commit

Permalink
Merge pull request #4 from nickovchinnikov/nick/basicTypes
Browse files Browse the repository at this point in the history
Nick/basic types
  • Loading branch information
nickovchinnikov authored Jun 21, 2021
2 parents 443013e + 6a35e9d commit ccc6f8d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
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,
};

0 comments on commit ccc6f8d

Please sign in to comment.