-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Search Terms
Export, typed exports, modules, Next.js, Redwood.js
Suggestion
Allow a new syntax From issue #420 that will allow typing all of exports in a module.
export implements {
default: string
foo: (bar: boolean) => number
}
export default "Hello world!";
export function foo(bar) { return 1 }
Use Cases and Examples
Increasingly frameworks are using named module exports as a way of organizing their code. For instance Next.js is using named exports to specify things like exported component and functions for fetching data:
import { PageModule } from 'next'
type Post = { title: string };
export implements PageModule<{ posts: Posts[] }>;
function Blog({ posts }) {
return (
<ul>
{posts.map(post => (
<li>{post.title}</li>
))}
</ul>
)
}
export async function getStaticProps() {
return { props: { posts: [] } }
}
export default Blog
Frameworks relying on named export
- Next.js
- Redwood.js
- Remix.js
- SevlteKit
- StroryBook
- CloudFlare Workers
-
please suggest more
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Related issues
poupryc, markozxuu, shahruz, naderhen, nicolasrouanne and 381 moredggsax, vimtor, rodrigo-roamdigital, joaopedrodcf, joshuajaco and 7 moretimsuchanek, LJMSU, OliverJAsh, gausie, kstratis and 32 moretimsuchanek, LJMSU, gausie, nanmon, tchak and 42 moretimsuchanek, StefanoA1, LJMSU, gausie, kstratis and 31 more
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript