Skip to content

Instantly share code, notes, and snippets.

@DanielHoffmann
Last active July 18, 2023 12:30
Show Gist options
  • Select an option

  • Save DanielHoffmann/ca4c7cbd4c32baf9086fecbaa871a8e7 to your computer and use it in GitHub Desktop.

Select an option

Save DanielHoffmann/ca4c7cbd4c32baf9086fecbaa871a8e7 to your computer and use it in GitHub Desktop.

Revisions

  1. DanielHoffmann revised this gist Jul 18, 2023. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion polymorphic.ts
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,5 @@ const c = {

    const a: A = c // valid
    Object.keys(a) // a, b, c
    a.d = 10 // error
    a.c = "c2" // error
    a.d = "d" // error
  2. DanielHoffmann revised this gist Jul 18, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion polymorphic.ts
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@

    type A = {
    a: string
    b: string
    @@ -6,8 +7,9 @@ type A = {
    const c = {
    a: 'a',
    b: 'b',
    c: 'c'
    c: 'c',
    }

    const a: A = c // valid
    Object.keys(a) // a, b, c
    a.d = 10 // error
  3. DanielHoffmann created this gist Jul 18, 2023.
    13 changes: 13 additions & 0 deletions polymorphic.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    type A = {
    a: string
    b: string
    }

    const c = {
    a: 'a',
    b: 'b',
    c: 'c'
    }

    const a: A = c // valid
    a.d = 10 // error