Skip to content

Instantly share code, notes, and snippets.

@alexbaumgertner
Last active May 8, 2021 17:56
Show Gist options
  • Save alexbaumgertner/10fedeaa14b6847f371127850b2d93f9 to your computer and use it in GitHub Desktop.
Save alexbaumgertner/10fedeaa14b6847f371127850b2d93f9 to your computer and use it in GitHub Desktop.

Revisions

  1. alexbaumgertner revised this gist May 8, 2021. No changes.
  2. alexbaumgertner revised this gist May 8, 2021. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions types.ts
    Original file line number Diff line number Diff line change
    @@ -44,3 +44,9 @@ const appPage = new AppPage(
    )

    appPage.page

    // WebStrom
    AppPage<lang.en>.page(): Page<T>

    // VSCode
    AppPage<lang.en>.page: Page<lang.en>
  3. alexbaumgertner created this gist May 8, 2021.
    46 changes: 46 additions & 0 deletions types.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    interface Page<T> {
    title: string;
    content: string;
    lang: T;
    }

    function getPage<T> (
    title: string,
    content: string,
    lang: T,
    ): Page<T> {
    return {
    title,
    content,
    lang,
    }
    }

    class AppPage<T> {
    constructor (
    private title: string,
    private content: string,
    private lang: T,
    ) {}

    public get page () {
    return getPage(
    this.title,
    this.content,
    this.lang,
    )
    }
    }

    enum lang {
    ru = 'ru',
    en = 'en',
    }

    const appPage = new AppPage(
    'App',
    'Hello, World!',
    lang.en as const,
    )

    appPage.page