Skip to content

Commit

Permalink
Rewind some of core typescript materials: Utility Types
Browse files Browse the repository at this point in the history
  • Loading branch information
zourdyzou committed Jun 24, 2022
1 parent d3cf0ab commit fd319fd
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions examples/Types/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type PermissionsWithoutAdminRole = Exclude<UserPermissionsRole, "admin">;

interface DepartmentsForPermissionRole {
depName: string;
levelClearence: number;
levelClearance: number;
}

const DepsForPermission: Record<
Expand All @@ -13,15 +13,15 @@ const DepsForPermission: Record<
> = {
admin: {
depName: "security engineer",
levelClearence: 10,
levelClearance: 10,
},
user: {
depName: "Sales Markerting",
levelClearence: 5,
levelClearance: 5,
},
manager: {
depName: "Marketing",
levelClearence: 10,
levelClearance: 10,
},
};

Expand All @@ -35,6 +35,37 @@ type BasicUser<A = boolean, P = TuplePermissions> = {
permissions?: P;
};

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>;

type BasicUserReadonlyRequired = Readonly<Required<BasicUser>>;

const user: FullUser<boolean> = {
name: "Nick",
surname: "Ovchinnikov",
age: 30,
isAdmin: true,
account: 100,
permissions: ["admin", "user"],
};

user.name = "Zourdy";

const usersArray: FullUser[] = [user, user];

function getFirstItem<T>(arr: T[]) {
return arr[0];
}

// getFirstItem<FullUser<boolean, TuplePermissions>>()

type BasicUserWithoutPermissions = Omit<BasicUser, "permissions">;

export {
Expand Down

0 comments on commit fd319fd

Please sign in to comment.