Easily Extend TypeScript Types In All Libraries!

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 พ.ย. 2024

ความคิดเห็น • 8

  • @emreaka3965
    @emreaka3965 ปีที่แล้ว

    Thank you. I encounter this in one of our legacy applications and I wanted to learn what that was for. In the first place, I've got a clue about what that is for but I just wanted to be sure and learn more about it.

  • @AyushKumar-po8no
    @AyushKumar-po8no 9 หลายเดือนก่อน

    That was actually very good content. Helped a lot.

  • @salkohajric6176
    @salkohajric6176 3 หลายเดือนก่อน

    Can you crate a video on how to change existing values or extend them

    • @covalence-io
      @covalence-io  2 หลายเดือนก่อน +1

      you should be able to change existing values the same way or just by redefining the interface. it should take the last definition that's been defined.

    • @salkohajric6176
      @salkohajric6176 2 หลายเดือนก่อน

      @@covalence-io and how to extend them? For example, if I have an object and keys a,b,c,d (all a string etc.) from some package and I simply want to make a little change and make the b to be number etc. and leave other fields typed as they are typed from the package itself

    • @covalence-io
      @covalence-io  2 หลายเดือนก่อน

      @@salkohajric6176 you could try something like this and use type B in your code instead of A. Rewriting the value of A doesn't make sense since there is clearly a library using that value as a string.
      interface A {
      x: string
      }
      export type B = Omit & { x: number };

  • @NavySturmGewehr
    @NavySturmGewehr 9 หลายเดือนก่อน

    I'm really struggling with this concept: What if I want to create a type definition library for my own javascript components? I want to be able to share types between a number of different projects, so I just want to npm install ../types and have access to namespace.mytype globally without imports (es6).

    • @covalence-io
      @covalence-io  9 หลายเดือนก่อน

      you could create your own npm package or add your types to a github repo and add the repo as a dependency to your package.json