Created
April 12, 2024 09:23
-
-
Save baptistemanson/06f0362221f4fe392c208bc59a49fd9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SOA | |
import { AppAccount, Collaborator } from "@prisma/client"; | |
// list of all row type in the app | |
enum TableRowTypeString { | |
Collaborator, | |
AppAccount, | |
} | |
// list of all fields for app accounts | |
enum AppAccountPaths { | |
role = "role", | |
status = "status", | |
} | |
// list of all fields for collaborator | |
enum CollaboratorPaths { | |
hello = "hello", | |
world = "world", | |
} | |
// list of all fields for all row types | |
type Fields = { | |
[TableRowTypeString.Collaborator]: CollaboratorPaths; | |
[TableRowTypeString.AppAccount]: AppAccountPaths; | |
}; | |
type TData = { | |
[TableRowTypeString.Collaborator]: Partial<Collaborator>; | |
[TableRowTypeString.AppAccount]: Partial<AppAccount>; | |
}; | |
// example of a type that forces a given enum based on the TableRowTypeString | |
type Column<T extends TableRowTypeString> = { | |
requiredFields: Fields[T]; | |
data: TData[T]; | |
}; | |
function getTextColumnDef<T extends TableRowTypeString>( | |
props: Partial<Column<T>> & { requiredFields: Fields[T] }, | |
): Column<T> { | |
return { ...props, data: { id: "a" } }; | |
} | |
const prout: Column<TableRowTypeString.AppAccount> = getTextColumnDef({ | |
requiredFields: AppAccountPaths.role, | |
}); | |
console.log(prout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment