Skip to content

Difference of Type and Interface #117

Description

@dzintars

Hi all. Could someone explain me an difference of:

export type FeatureState = Readonly<{
  entities: { [id: string]: Entity }
  ids: string[]
}>

and

interface FeatureState {
  readonly entities: { [id: string]: Entity }
  readonly ids: string[]
}

?

phryneasToday at 10:48 AM
@dzintars There is none. Readonly is a mapped type that creates the second type
Well, minor differences. One is an interface and one is a type.
https://twitter.com/phry/status/1222241038884048896

Lenz Weber (@phry)
This #TypeScriptTuesday, we're going to take a look at #TypeScript's interfaces.
Interfaces are different from types and both have their strengths in different situations.
Let's take a look.
This is just some interface definition - again an example from the #redux types:
🧵👇

But in this situation that probably should not concern you, apart from the different "mouseover" behaviour

DzintarsToday at 11:00 AM
Thank you! Then.. what does the "industry" chooses in this context? Just interfaces?

phryneasToday at 11:02 AM
I've not seen any preference for one or the other really.

DzintarsToday at 11:35 AM
That tweet is really good. Thank you.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions