Skip to content

03_02e The source code doesn't match the video source; #1

@andriussok

Description

@andriussok

Issue Overview

03_02e The source code doesn't match the video source;

Possible Solution

add extra code if you want, but keep the code from the video in the source;

type ContactName = string;
type ContactStatus = "active" | "inactive" | "new"
type ContactBirthDate = Date | number | string

interface Contact {
    id: number;
    name: ContactName;
    birthDate?: ContactBirthDate;
    status?: ContactStatus;
    email?: string;
}

let primaryContact: Contact = {
    id: 12345,
    name: "James Johnson",
    status: "active"
}

type ContactFields = keyof Contact

function getValue<T, U extends keyof T>(source: T, propertyName: U) {
    return source[propertyName]
}
const value = getValue({min: 1, max: 200}, "");

// function toContact(nameOrContact) {
//     if (typeof nameOrContact === "string") {
//         return {
//             id: 0,
//             name: nameOrContact,
//             status: "active"
//         }
//     }
//     else if (typeof nameOrContact === "object") {
//         return {
//             id: nameOrContact.id,
//             name: nameOrContact.name,
//             status: nameOrContact.status
//         }
//     }
//     else {
//         return null;
//     }
// }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions