We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Branded Types can help prevent common errors by ensuring that certain values are only used in specific contexts.
The laravel-typegen generates the following:
laravel-typegen
type Brand<K, T> = K & { __brand: T } type UserId = Brand<number, "UserId"> type User = { id: UserId; loginid?: string; }
The generated model type can be used as follows.
function showUserInfo(user: User) { return `${user.id}: ${user.name}` } const user1Id = 123 as UserId const user1 = { id: user1Id, name: 'Jone Doe' } console.log(showUserInfo(user1)) // OK console.log(showUserInfo({ userId: 123, name: 'Jone Doe' })) // Error
The text was updated successfully, but these errors were encountered:
7nohe
No branches or pull requests
Branded Types can help prevent common errors by ensuring that certain values are only used in specific contexts.
The
laravel-typegen
generates the following:The generated model type can be used as follows.
The text was updated successfully, but these errors were encountered: