Skip to content

Commit

Permalink
Strict null checks! (#845)
Browse files Browse the repository at this point in the history
* Turn strictNullChecks on

Also updates launch.json and tasks.json to be more helpful in VSCode and enables downlevelIteration.

In order to fix some of the unit tests, the target was updated to es2015 - since the lib already references es2015 libraries and we are only testing on node 6+, I believe this is acceptable.

* Remove yarn error log, add to .gitignore

Also updates launch.json and tasks.json to be more helpful in VSCode and enables downlevelIteration.

In order to fix some of the unit tests, the target was updated to es2015 - since the lib already references es2015 libraries and we are only testing on node 6+, I believe this is acceptable.

* Fix missing implemented interfaces

* Pin highlight.js version to 9.12.0
  • Loading branch information
Gerrit0 authored and aciccarello committed Oct 20, 2018
1 parent 7799a89 commit a2fab7c
Show file tree
Hide file tree
Showing 129 changed files with 1,031 additions and 1,004 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.baseDir.js
.baseDir.ts
yarn.lock
yarn-error.log

/src/typings/typescript/typescript.js

Expand Down
8 changes: 5 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"name": "Debug Tests",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"cwd": "${workspaceRoot}",
"args": [
"--no-timeouts"
"--no-timeouts",
"dist/test/**/*.js"
],
"outFiles": [
"${workspaceRoot}/lib/**/*.js",
"${workspaceRoot}/test/**/*.js"
],
"preLaunchTask": "build",
"sourceMaps": true
}
]
}
}
32 changes: 22 additions & 10 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-w", "-p", "."],
"showOutput": "silent",
"isWatching": true,
"problemMatcher": "$tsc-watch"
}
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"identifier": "build",
"type": "grunt",
"task": "default",
"problemMatcher": [
"$tsc"
]
},
{
"identifier": "build_and_test",
"type": "grunt",
"task": "build_and_test",
"problemMatcher": [
"$tsc"
]
}
]
}
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@types/shelljs": "^0.8.0",
"fs-extra": "^7.0.0",
"handlebars": "^4.0.6",
"highlight.js": "^9.0.0",
"highlight.js": "9.12.0",
"lodash": "^4.17.10",
"marked": "^0.4.0",
"minimatch": "^3.0.0",
Expand Down
20 changes: 10 additions & 10 deletions src/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Serializer } from './serialization';
import { ProjectReflection } from './models/index';
import { Logger, ConsoleLogger, CallbackLogger, PluginHost, writeFile } from './utils/index';

import { AbstractComponent, ChildableComponent, Component, Option } from './utils/component';
import { AbstractComponent, ChildableComponent, Component, Option, DUMMY_APPLICATION_OWNER } from './utils/component';
import { Options, OptionsReadMode, OptionsReadResult } from './utils/options/index';
import { ParameterType } from './utils/options/declaration';

Expand Down Expand Up @@ -67,21 +67,21 @@ export class Application extends ChildableComponent<Application, AbstractCompone
defaultValue: 'console',
type: ParameterType.Mixed
})
loggerType: string|Function;
loggerType!: string|Function;

@Option({
name: 'ignoreCompilerErrors',
help: 'Should TypeDoc generate documentation pages even after the compiler has returned errors?',
type: ParameterType.Boolean
})
ignoreCompilerErrors: boolean;
ignoreCompilerErrors!: boolean;

@Option({
name: 'exclude',
help: 'Define patterns for excluded files when specifying paths.',
type: ParameterType.Array
})
exclude: Array<string>;
exclude!: Array<string>;

/**
* The version number of TypeDoc.
Expand All @@ -94,7 +94,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
* @param options An object containing the options that should be used.
*/
constructor(options?: Object) {
super(null);
super(DUMMY_APPLICATION_OWNER);

this.logger = new ConsoleLogger();
this.converter = this.addComponent<Converter>('converter', Converter);
Expand Down Expand Up @@ -153,9 +153,9 @@ export class Application extends ChildableComponent<Application, AbstractCompone
* Run the converter for the given set of files and return the generated reflections.
*
* @param src A list of source that should be compiled and converted.
* @returns An instance of ProjectReflection on success, NULL otherwise.
* @returns An instance of ProjectReflection on success, undefined otherwise.
*/
public convert(src: string[]): ProjectReflection {
public convert(src: string[]): ProjectReflection | undefined {
this.logger.writeln('Using TypeScript %s from %s', this.getTypeScriptVersion(), this.getTypeScriptPath());

const result = this.converter.convert(src);
Expand All @@ -165,7 +165,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
this.logger.resetErrors();
return result.project;
} else {
return null;
return;
}
} else {
return result.project;
Expand All @@ -188,7 +188,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
* @param out The path the documentation should be written to.
* @returns TRUE if the documentation could be generated successfully, otherwise FALSE.
*/
public generateDocs(input: any, out: string): boolean {
public generateDocs(input: ProjectReflection | string[], out: string): boolean {
const project = input instanceof ProjectReflection ? input : this.convert(input);
if (!project) {
return false;
Expand Down Expand Up @@ -246,7 +246,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
* @param inputFiles The list of files that should be expanded.
* @returns The list of input files with expanded directories.
*/
public expandInputFiles(inputFiles?: string[]): string[] {
public expandInputFiles(inputFiles: string[] = []): string[] {
let files: string[] = [];
const exclude: Array<IMinimatch> = this.exclude ? this.exclude.map(pattern => new Minimatch(pattern, {dot: true})) : [];

Expand Down
11 changes: 5 additions & 6 deletions src/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,38 @@ export class CliApplication extends Application {
help: 'Specifies the location the documentation should be written to.',
hint: ParameterHint.Directory
})
out: string;
out!: string;

@Option({
name: 'json',
help: 'Specifies the location and file name a json file describing the project is written to.',
hint: ParameterHint.File
})
json: string;
json!: string;

@Option({
name: 'version',
short: 'v',
help: 'Print the TypeDoc\'s version.',
type: ParameterType.Boolean
})
version: boolean;
version!: boolean;

@Option({
name: 'help',
short: 'h',
help: 'Print this message.',
type: ParameterType.Boolean
})
help: boolean;
help!: boolean;

/**
* Run TypeDoc from the command line.
*/
protected bootstrap(options?: Object): OptionsReadResult {
const result = super.bootstrap(options);
if (result.hasErrors) {
process.exit(ExitCode.OptionError);
return;
return process.exit(ExitCode.OptionError);
}

if (this.version) {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/converter/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export abstract class ConverterNodeComponent<T extends ts.Node> extends Converte
/**
* List of supported TypeScript syntax kinds.
*/
supports: ts.SyntaxKind[];
abstract supports: ts.SyntaxKind[];

abstract convert(context: Context, node: T): Reflection;
abstract convert(context: Context, node: T): Reflection | undefined;
}

export abstract class ConverterTypeComponent extends ConverterComponent {
Expand All @@ -39,17 +39,17 @@ export interface TypeTypeConverter<T extends ts.Type> extends ConverterTypeCompo
/**
* Convert the given type to its type reflection.
*/
convertType(context: Context, type: T): Type;
convertType(context: Context, type: T): Type | undefined;
}

export interface TypeNodeConverter<T extends ts.Type, N extends ts.Node> extends ConverterTypeComponent {
/**
* Test whether this converter can handle the given TypeScript node.
*/
supportsNode(context: Context, node: N, type: T): boolean;
supportsNode(context: Context, node: N, type: T | undefined): boolean;

/**
* Convert the given type node to its type reflection.
*/
convertNode(context: Context, node: N, type: T): Type;
convertNode(context: Context, node: N, type: T | undefined): Type | undefined;
}
Loading

0 comments on commit a2fab7c

Please sign in to comment.