You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(egg): implement defineConfig helper for type intellisense (#5531)
This PR implements the `defineConfig` helper function that provides
type-safe configuration definition for Egg.js applications. Users can
now import and use it as:
```typescript
import { defineConfig } from 'egg';
export default defineConfig({
keys: 'my-keys',
middleware: ['cors']
});
```
## What's New
The `defineConfig` function supports two usage patterns:
**Static Configuration:**
```typescript
export default defineConfig({
keys: 'my-secret-key',
middleware: ['cors', 'bodyParser'],
logger: {
level: 'INFO'
}
});
```
**Dynamic Configuration with Function:**
```typescript
export default defineConfig((appInfo) => ({
keys: `${appInfo.name}_${appInfo.env}_keys`,
middleware: [],
customConfig: {
version: appInfo.pkg.version,
sourceUrl: `https://example.com/${appInfo.name}`
}
}));
```
## Implementation Details
- **Type Safety**: Leverages existing `PowerPartial<EggAppConfig>` for
full TypeScript support with IntelliSense
- **Flexibility**: Accepts both static objects and factory functions
that receive `EggAppInfo`
- **Extensibility**: Allows custom configuration properties alongside
built-in Egg.js config options
- **Zero Runtime Overhead**: Simple pass-through function that preserves
the original config
- **Backward Compatible**: Doesn't break any existing configuration
patterns
## Developer Experience
The function provides excellent TypeScript support with:
- Auto-completion for all built-in Egg.js configuration options
- Type checking for configuration values
- Support for extending with custom business configuration
- Clear JSDoc documentation with usage examples
## Updated Templates
Only Egg4 scaffolding templates have been updated to demonstrate the
modern `defineConfig` usage pattern while maintaining the same
functionality. Egg3 templates remain unchanged to preserve backward
compatibility.
Fixes#5516.
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: fengmk2 <[email protected]>
Co-authored-by: MK <[email protected]>
0 commit comments