#How to default export an object of an interface type in TS

53 messages · Page 1 of 1 (latest)

balmy shuttle

module.exports = { ... }
export default { ... }

since you're using ts, you should be using esm-like syntax

pallid blade

ik how to do that

balmy shuttle

cjs imports/exports will be generated upon compilation

pallid blade

but how do I make the type of my interface type

like make module.exports Command type

balmy shuttle

you don't really need to do that

ts is structurally typed

you could do one of these

const command: Command = { ... };
export default command;
``````ts
export default { ... } satisfies Command;
pallid blade

I have seen the first one

long but could work

but what is the second one?

satisfies?

balmy shuttle

it's relatively new

pallid blade

ah

should I use 1 or 2 then?

balmy shuttle
pallid blade

since 2 is newer I assume 1

balmy shuttle

what pattern do you like more

pallid blade
pallid blade
balmy shuttle
pallid blade

but the first one is simple but longer

balmy shuttle

but again, up to you

if you prefer the former, go ahead

pallid blade

since I want this to go into a repo

balmy shuttle

i wouldn't recommend either over the other without context tbh

i personally would use a class

pallid blade
balmy shuttle

yeah

pallid blade

this is what I am using it for

balmy shuttle

that's specific to me though, i use java as well so the patterns leak through in my mind

pallid blade
pallid blade

but since I started using TS I realized there are faster ways

balmy shuttle

i have a public repo that i use for bots that kinda has a framework (im working on separating out the framework, but i haven't had time)
you could try checking that out if you want to use classes

pallid blade

oooh

balmy shuttle

only other thing i can really recommend you is the ts server for more opinions

pallid blade

could you send a link?

pallid blade

besides for me this is a very nitty gritty scenario

like I have never had such specific things needed

balmy shuttle

i don't have enough free time lmao

pallid blade

oh ok

pallid blade
balmy shuttle

(both the repos that are referenced in the main readme are currently local, those will yield 404s)