Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions packages/typir/src/typir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,11 @@ export function createTypirServices<LanguageType>(
);
}

// TODO Review: Is it possible to merge/unify these two functions in a nice way?

/**
* Creates the TypirServices with the default module containing the default implements for Typir,
Comment thread
JohannesMeierSE marked this conversation as resolved.
Outdated
* which might be exchanged by the given optional customized modules.
* Additionally, some new services are defined, and implementations for them are registered.
* @param moduleForAdditionalServices contains configurations for all added services
* @param moduleForAdditionalServices contains the configurations for all added services
* @param customization1 optional Typir module with customizations (for new and existing services)
* @param customization2 optional Typir module with customizations (for new and existing services)
* @param customization3 optional Typir module with customizations (for new and existing services)
Expand All @@ -161,6 +159,31 @@ export function createTypirServicesWithAdditionalServices<LanguageType, Addition
);
}

// TODO Review: Is it possible to merge/unify the two functions above in a nice way?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this question. Could we discuss this?


// The following function is a possible solution, but with a small limitation:
// - If you specify non-empty additional services via the <AdditionalServices> generic, you will get no TypeScript compiler error,
// if you don't specify a value for 'moduleForAdditionalServices'. (Doing that makes no sense of course, but a hint would be nice nevertheless.)
// 'moduleForAdditionalServices' needs to be optional, otherwise, you need to add '{}' as value even when you specified no additional services.

export function createTypirServicesBoth<LanguageType, AdditionalServices = Record<string, never>>( // "Record<string, never>" means an empty object!
moduleForAdditionalServices?: Module<TypirServices<LanguageType> & AdditionalServices, AdditionalServices>,
customization1?: Module<TypirServices<LanguageType> & AdditionalServices, DeepPartial<TypirServices<LanguageType> & AdditionalServices>>,
customization2?: Module<TypirServices<LanguageType> & AdditionalServices, DeepPartial<TypirServices<LanguageType> & AdditionalServices>>,
customization3?: Module<TypirServices<LanguageType> & AdditionalServices, DeepPartial<TypirServices<LanguageType> & AdditionalServices>>,
): TypirServices<LanguageType> & AdditionalServices {
return inject(
// use the default implementations for all core Typir services
createDefaultTypirServicesModule<LanguageType>(),
moduleForAdditionalServices,
// optionally add some more language-specific customization, e.g. for ...
customization1, // ... production
customization2, // ... testing (in order to replace some customizations of production)
customization3, // ... testing (e.g. to have customizations for all test cases and for single test cases)
);
}


/**
* A deep partial type definition for services. We look into T to see whether its type definition contains
* any methods. If it does, it's one of our services and therefore should not be partialized.
Expand Down