type SessionAttributes = { email: string isAdmin: boolean provider: string termsOfServiceSigned: boolean unsignedClientContracts: string[] unsignedOwnerContracts: string[] wishlistToken: null | string incompleteSignup: boolean } type SessionOptions = { serialized?: boolean fields?: 'attributes' | 'id' | 'type' optionalAttributes?: boolean } type SessionFieldsCondition = Options['fields'] extends keyof SessionFields ? Options['fields'] : keyof SessionFields type SessionAttributesCondition = AttributeOptions extends true ? Partial : SessionAttributes type SessionFields = { attributes: SessionAttributesCondition id: string type: string } type SessionCondition = Options['serialized'] extends true ? 'id' : keyof SessionFields type SessionFieldsPick = Pick< SessionFields, SessionFieldsCondition > type SessionSerialize = Pick< SessionFieldsPick, SessionCondition > & SessionAttributesCondition export type Session< Options extends SessionOptions = { serialized: false optionalAttributes: false }, > = Options['serialized'] extends true ? SessionSerialize : SessionFieldsPick