aws-amplify / aws-amplify/amplify-data
Export ModelTypesClient type from @aws-amplify/data-schema for better TypeScript support
- Dominant language
- TypeScript
- Stars
- 18
- Forks
- 23
- Avg merge
- 26m
- Merged PRs (30d)
- 1
Description
### Is this related to a new or existing framework?
_No response_
### Is this related to a new or existing API?
_No response_
### Is this related to another service?
_No response_
### Describe the feature you'd like to request
I would like the `ModelTypesClient` type to be exported from `@aws-amplify/data-schema/dist/esm/runtime/client`. Currently, this type exists internally but is not accessible to developers, forcing us to manually recreate complex type mappings when building custom wrappers around Amplify Data client operations.
This creates significant boilerplate code (80+ lines) for type-safe wrapper implementations that could be eliminated with proper type exports. The feature would enable developers to create domain-specific service layers, add custom error handling, and build reusable data access patterns with full TypeScript support.
### Describe the solution you'd like
Export the `ModelTypesClient` type from the public API to enable direct usage:
```typescript
// Current workaround (80+ lines of boilerplate)
type ModelTypeMap = {
User: {
createType: Schema["User"]["createType"];
type: Schema["User"]["type"];
updateType: Schema["User"]["updateType"];
deleteType: Schema["User"]["deleteType"];
};
// ... repeat for each model + 50+ lines of wrapper implementation
};
// Proposed solution (simple and clean)
import type { ModelTypesClient } from "@aws-amplify/data-schema/dist/esm/runtime/client";
import type { Schema } from "amplify/data/resource";
export const wUser: ModelTypesClient = client.models.User;
export const wAnimal: ModelTypesClient = client.models.Animal;
```
The implementation would require adding `export type { ModelTypesClient }` to `@aws-amplify/data-schema/src/runtime/client/index.ts`.
### Describe alternatives you've considered
1. **Manual type recreation**: Currently using hand-written type mappings and wrapper functions, but this requires maintenance and doesn't automatically sync with schema changes.
2. **Using `ModelTypes` directly**: Attempted to use the exported `ModelTypes`, but its structure is different (contains method signatures rather than type mappings), making it unsuitable for our use case.
3. **Type assertion with `any`**: Could bypass TypeScript checking entirely, but this eliminates type safety benefits and goes against TypeScript best practices.
4. **Accessing internal types**: Could import from internal paths, but this is fragile and may break with updates.
None of these alternatives provide the clean, maintainable, and type-safe solution that exporting `ModelTypesClient` would offer.
### Additional context
_No response_
### Is this something that you'd be interested in working on?
- [x] 👋 I may be able to implement this feature request
- [ ] ⚠️ This feature might incur a breaking change
Contributor guide
Research direction
Read @aws-amplify/data-schema/src/runtime/client/index.ts and confirm how the client runtime types are exposed. Add the requested public type export, then verify the package's generated declarations or type-checking expose ModelTypesClient from the documented client path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, developer-experience
- Issue type
- Feature
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100