#What are the ramifications of returning a non-exported return type?

15 messages · Page 1 of 1 (latest)

meager gullBOT
#
bawdyinkslinger#0

Preview:```ts
type Return = {
foo: string
}

export function x(): Return {
return {foo: "bar"}
}```

prisma stream
#

!ts

meager gullBOT
#
type Return = {
  foo: string;
};

export function x(): Return {
  return { foo: "bar" };
}
prisma stream
#

In these situations, I always export my type too. But I've always wondered what are the ramifications to making the Return type internal only?

#

Pros and cons, etc.?

arctic kindle
#

Even if it's not exported explicitly, it still is implicitly because you can access it by ReturnType<typeof x>

#

It's probably better to export the type though if you're building some kind of library

prisma stream
#

Guessing the IDE would still guide you to the correct shape

arctic kindle
#

Not duck typing, it's part of the function signature

#

It's more whether you can access it directly as a standalone thing, or access it as the return type of this particular function

prisma stream
#

ah, okay

#

Is there anything else to consider?

arctic kindle
#

Not AFAIK

#

Outside of "style" concerns