Skip to content

Commit a2fab7c

Browse files
Gerrit0aciccarello
authored andcommitted
Strict null checks! (#845)
* 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
1 parent 7799a89 commit a2fab7c

File tree

129 files changed

+1031
-1004
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1031
-1004
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.baseDir.js
55
.baseDir.ts
66
yarn.lock
7+
yarn-error.log
78

89
/src/typings/typescript/typescript.js
910

.vscode/launch.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
{
88
"type": "node",
99
"request": "launch",
10-
"name": "Launch Program",
10+
"name": "Debug Tests",
1111
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
1212
"cwd": "${workspaceRoot}",
1313
"args": [
14-
"--no-timeouts"
14+
"--no-timeouts",
15+
"dist/test/**/*.js"
1516
],
1617
"outFiles": [
1718
"${workspaceRoot}/lib/**/*.js",
1819
"${workspaceRoot}/test/**/*.js"
1920
],
21+
"preLaunchTask": "build",
2022
"sourceMaps": true
2123
}
2224
]
23-
}
25+
}

.vscode/tasks.json

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
{
2-
// See https://go.microsoft.com/fwlink/?LinkId=733558
3-
// for the documentation about the tasks.json format
4-
"version": "0.1.0",
5-
"command": "tsc",
6-
"isShellCommand": true,
7-
"args": ["-w", "-p", "."],
8-
"showOutput": "silent",
9-
"isWatching": true,
10-
"problemMatcher": "$tsc-watch"
11-
}
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"identifier": "build",
8+
"type": "grunt",
9+
"task": "default",
10+
"problemMatcher": [
11+
"$tsc"
12+
]
13+
},
14+
{
15+
"identifier": "build_and_test",
16+
"type": "grunt",
17+
"task": "build_and_test",
18+
"problemMatcher": [
19+
"$tsc"
20+
]
21+
}
22+
]
23+
}

package-lock.json

Lines changed: 30 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@types/shelljs": "^0.8.0",
4040
"fs-extra": "^7.0.0",
4141
"handlebars": "^4.0.6",
42-
"highlight.js": "^9.0.0",
42+
"highlight.js": "9.12.0",
4343
"lodash": "^4.17.10",
4444
"marked": "^0.4.0",
4545
"minimatch": "^3.0.0",

src/lib/application.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Serializer } from './serialization';
1717
import { ProjectReflection } from './models/index';
1818
import { Logger, ConsoleLogger, CallbackLogger, PluginHost, writeFile } from './utils/index';
1919

20-
import { AbstractComponent, ChildableComponent, Component, Option } from './utils/component';
20+
import { AbstractComponent, ChildableComponent, Component, Option, DUMMY_APPLICATION_OWNER } from './utils/component';
2121
import { Options, OptionsReadMode, OptionsReadResult } from './utils/options/index';
2222
import { ParameterType } from './utils/options/declaration';
2323

@@ -67,21 +67,21 @@ export class Application extends ChildableComponent<Application, AbstractCompone
6767
defaultValue: 'console',
6868
type: ParameterType.Mixed
6969
})
70-
loggerType: string|Function;
70+
loggerType!: string|Function;
7171

7272
@Option({
7373
name: 'ignoreCompilerErrors',
7474
help: 'Should TypeDoc generate documentation pages even after the compiler has returned errors?',
7575
type: ParameterType.Boolean
7676
})
77-
ignoreCompilerErrors: boolean;
77+
ignoreCompilerErrors!: boolean;
7878

7979
@Option({
8080
name: 'exclude',
8181
help: 'Define patterns for excluded files when specifying paths.',
8282
type: ParameterType.Array
8383
})
84-
exclude: Array<string>;
84+
exclude!: Array<string>;
8585

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

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

161161
const result = this.converter.convert(src);
@@ -165,7 +165,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
165165
this.logger.resetErrors();
166166
return result.project;
167167
} else {
168-
return null;
168+
return;
169169
}
170170
} else {
171171
return result.project;
@@ -188,7 +188,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
188188
* @param out The path the documentation should be written to.
189189
* @returns TRUE if the documentation could be generated successfully, otherwise FALSE.
190190
*/
191-
public generateDocs(input: any, out: string): boolean {
191+
public generateDocs(input: ProjectReflection | string[], out: string): boolean {
192192
const project = input instanceof ProjectReflection ? input : this.convert(input);
193193
if (!project) {
194194
return false;
@@ -246,7 +246,7 @@ export class Application extends ChildableComponent<Application, AbstractCompone
246246
* @param inputFiles The list of files that should be expanded.
247247
* @returns The list of input files with expanded directories.
248248
*/
249-
public expandInputFiles(inputFiles?: string[]): string[] {
249+
public expandInputFiles(inputFiles: string[] = []): string[] {
250250
let files: string[] = [];
251251
const exclude: Array<IMinimatch> = this.exclude ? this.exclude.map(pattern => new Minimatch(pattern, {dot: true})) : [];
252252

src/lib/cli.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,38 @@ export class CliApplication extends Application {
2020
help: 'Specifies the location the documentation should be written to.',
2121
hint: ParameterHint.Directory
2222
})
23-
out: string;
23+
out!: string;
2424

2525
@Option({
2626
name: 'json',
2727
help: 'Specifies the location and file name a json file describing the project is written to.',
2828
hint: ParameterHint.File
2929
})
30-
json: string;
30+
json!: string;
3131

3232
@Option({
3333
name: 'version',
3434
short: 'v',
3535
help: 'Print the TypeDoc\'s version.',
3636
type: ParameterType.Boolean
3737
})
38-
version: boolean;
38+
version!: boolean;
3939

4040
@Option({
4141
name: 'help',
4242
short: 'h',
4343
help: 'Print this message.',
4444
type: ParameterType.Boolean
4545
})
46-
help: boolean;
46+
help!: boolean;
4747

4848
/**
4949
* Run TypeDoc from the command line.
5050
*/
5151
protected bootstrap(options?: Object): OptionsReadResult {
5252
const result = super.bootstrap(options);
5353
if (result.hasErrors) {
54-
process.exit(ExitCode.OptionError);
55-
return;
54+
return process.exit(ExitCode.OptionError);
5655
}
5756

5857
if (this.version) {

src/lib/converter/components.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export abstract class ConverterNodeComponent<T extends ts.Node> extends Converte
1414
/**
1515
* List of supported TypeScript syntax kinds.
1616
*/
17-
supports: ts.SyntaxKind[];
17+
abstract supports: ts.SyntaxKind[];
1818

19-
abstract convert(context: Context, node: T): Reflection;
19+
abstract convert(context: Context, node: T): Reflection | undefined;
2020
}
2121

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

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

5151
/**
5252
* Convert the given type node to its type reflection.
5353
*/
54-
convertNode(context: Context, node: N, type: T): Type;
54+
convertNode(context: Context, node: N, type: T | undefined): Type | undefined;
5555
}

0 commit comments

Comments
 (0)