#still a bit confused by the difference between `interface` and `type`
19 messages ยท Page 1 of 1 (latest)
Afaik, interface is extend-able, but type is not. And interface is sort of made for "object", but for type you can do string and number more. Apart from these subtle difference, i think the two can still be used interchangabily ๐ค
feels to me like they could've just made just one keyword to do it all? idk
ts documentation sort of explains it a bit. See if it can ans ur problem.
The language primitives.
Yes, you are right, minus a few edge cases, type is just a more powerful interface. My guess is if they could start from scratch, it'd be just one keyword.
oh oops, i'd have guessed interfaces were more powerful
because of inheritance
It's just a weird form of intersection
yeah i didn't actually know about the & operator until today haha
The only thing interfaces can do fundamentally that types can't is use a this type. If support were added for types I wouldn't use interfaces for anything
do you think they would ever add that in?
I couldn't find any issues on GitHub proposing it, though there must be one somewhere. I'd guess probably not.
ArkType allows it ๐
what's arktype?
It's a runtime validation library I'm working on that mirrors TypeScript's syntax (with some extensions) https://github.com/arktypeio/arktype
This is not pure typescript. The keyword this can not be used to correlate properties within an object type.
Sorry what isn't pure typescript? I know this is not available in types, you can use it to reference other properties in an interface though