lisk-sdk icon indicating copy to clipboard operation
lisk-sdk copied to clipboard

Replace Interfaces with `type` , `type alias` & `intersection`

Open sitetester opened this issue 2 years ago • 3 comments

Description

Currently we have interfaces with similar elements. We can replace them using type, type alias & intersection feature.

Motivation

Elements are duplicated. We can simply use type alias for an existing type & merge similar types using intersection

Additional Information

  • https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-aliases
  • https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#differences-between-type-aliases-and-interfaces
Screenshot 2022-08-09 at 03 17 20 PM

sitetester avatar Aug 09 '22 12:08 sitetester

Do you mean replace all interfaces with types or only in applicable scenarios?

For the above issue, you can solve it by extending the Keys interface e.g.

image

By extending an interface, we can reduce the duplication. In my humble opinion, this is not an interface issue but more of a design issue as you can still have duplication with type/type aliases as well.

mosmartin avatar Aug 09 '22 19:08 mosmartin

  • Only in current file

  • Yes, code duplication could be avoided using extending interface also. Not sure, if AuthAccount really extends Keys from OOP perspective. Since they are not directly parent/child, hence type seems a better alternative.

  • Using type alias (there is no duplication)

type RegisterMultisignatureParams = Keys

sitetester avatar Aug 10 '22 09:08 sitetester

Also here framework/src/modules/reward/types.ts

sitetester avatar Aug 12 '22 13:08 sitetester

Closing this issue for no activity

shuse2 avatar Dec 20 '23 17:12 shuse2