microsoft / microsoft/TypeScript
Type annotation for all exports in the module
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the proposed syntax and the related issues #420 and #13626. Compare the requested behavior with the Next.js, Redwood.js, Remix.js, SvelteKit, Storybook, and Cloudflare Workers use cases; the issue names no target files or tests, so the syntax and implementation scope would need to be established first.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100