Skip to content

Commit 5724aae

Browse files
committed
Eliminate partial type
1 parent 15922af commit 5724aae

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

apps/api-extractor/src/api/ExtractorConfig.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface IExtractorConfigParseConfigObjectOptions {
5353
/**
5454
* An already prepared configuration object as returned by {@link ExtractorConfig.loadJsonFileWithInheritance}.
5555
*/
56-
configObject: Partial<IExtractorConfig>;
56+
configObject: IExtractorConfig;
5757

5858
/**
5959
* The absolute path of the file that the `configObject` object was loaded from. This is used for error messages
@@ -232,7 +232,7 @@ export class ExtractorConfig {
232232
*/
233233
public static loadAndParseConfig(configJsonFilePath: string): ExtractorConfig {
234234
const configObjectFullPath: string = path.resolve(configJsonFilePath);
235-
const configObject: Partial<IExtractorConfig> = ExtractorConfig.loadJsonFileWithInheritance(configObjectFullPath);
235+
const configObject: IExtractorConfig = ExtractorConfig.loadJsonFileWithInheritance(configObjectFullPath);
236236

237237
const packageJsonLookup: PackageJsonLookup = new PackageJsonLookup();
238238
const packageJsonFullPath: string | undefined = packageJsonLookup.tryGetPackageJsonFilePathFor(
@@ -257,7 +257,7 @@ export class ExtractorConfig {
257257
* If the "extends" field is present, the referenced file(s) will be merged,
258258
* along with the API Extractor defaults.
259259
*/
260-
public static loadJsonFileWithInheritance(jsonFilePath: string): Partial<IExtractorConfig> {
260+
public static loadJsonFileWithInheritance(jsonFilePath: string): IExtractorConfig {
261261
// Set to keep track of config files which have been processed.
262262
const visitedPaths: Set<string> = new Set<string>();
263263

@@ -310,7 +310,10 @@ export class ExtractorConfig {
310310
// Lastly, apply the defaults
311311
configObject = lodash.merge(lodash.cloneDeep(ExtractorConfig._defaultConfig), configObject);
312312

313-
return configObject;
313+
ExtractorConfig.jsonSchema.validateObject(configObject, jsonFilePath);
314+
315+
// The schema validation should ensure that this object conforms to IExtractorConfig
316+
return configObject as IExtractorConfig;
314317
}
315318

316319
/**

apps/api-extractor/src/cli/RunAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class RunAction extends CommandLineAction {
123123
}
124124

125125
const configFullPath: string = path.resolve(configFilename);
126-
const mergedConfig: Partial<IExtractorConfig> = ExtractorConfig.loadJsonFileWithInheritance(configFullPath);
126+
const mergedConfig: IExtractorConfig = ExtractorConfig.loadJsonFileWithInheritance(configFullPath);
127127

128128
const extractorConfig: ExtractorConfig = ExtractorConfig.parseConfigObject({
129129
configObject: mergedConfig,

common/reviews/api/api-extractor.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class ExtractorConfig {
3535
static hasDtsFileExtension(filePath: string): boolean;
3636
static readonly jsonSchema: JsonSchema;
3737
static loadAndParseConfig(configJsonFilePath: string): ExtractorConfig;
38-
static loadJsonFileWithInheritance(jsonFilePath: string): Partial<IExtractorConfig>;
38+
static loadJsonFileWithInheritance(jsonFilePath: string): IExtractorConfig;
3939
readonly mainEntryPointFile: string;
4040
readonly messages: IExtractorMessagesConfig;
4141
readonly overrideTsconfig: {} | undefined;
@@ -146,7 +146,7 @@ export interface IExtractorConfig {
146146

147147
// @public
148148
export interface IExtractorConfigParseConfigObjectOptions {
149-
configObject: Partial<IExtractorConfig>;
149+
configObject: IExtractorConfig;
150150
configObjectFullPath: string | undefined;
151151
packageJson?: INodePackageJson | undefined;
152152
packageJsonFullPath: string | undefined;

0 commit comments

Comments
 (0)