Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict null checks! #845

Merged
merged 30 commits into from Oct 20, 2018
Merged

Conversation

Gerrit0
Copy link
Collaborator

@Gerrit0 Gerrit0 commented Aug 27, 2018

This touches a... lot of code. Fortunately, most of it is trivial changes.

The highlights:

  1. Turned on strictNullChecks, strictPropertyInitialization in tsconfig.json
  2. Turned on no-for-in-array, strict-type-predicates in tslint.json

Needs attention:

  1. I changed the tsconfig target from es5 to es2015. This change was made in order to make the ReflectionFlags class act as a class. Since the lib property already includes es2015 libraries, and we only test on node 6+, I believe this is a justifiable change.
  2. In order to make the .application and .owner properties in components type correctly, I added a symbol which is used to identify the root component, an alternative choice would be to make the .owner and .application properties nullable, which might be desirable if components will ever be used without an application (possible?)
  3. I've added several interfaces marked as internal in the Typescript library to replace a single interface which was inaccurate. I'd like to remove the reliance on internal apis, but it works for now...

Gerrit0 and others added 8 commits August 25, 2018 15:59
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.
Adding localization plugin in the plugin section. 

This plugin will ease every user, to:
1. Generate a json files with all code comments based on the project structure
2. Edit the json with the translation on the desired language
3. Re-generate the typodoc documentation with the updated jason for the new language
Copy link
Collaborator

@aciccarello aciccarello left a comment

Choose a reason for hiding this comment

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

Sorry for being slow to respond. I only was able to get partially through the PR but would like to start the feedback loop early. I see some improvements could be made to avoid ! nullable assertions but as I've thought about it, those improvements might be suited for another PR.

Overall this should help make the code easier to reason about so thanks for putting this together!

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

Choose a reason for hiding this comment

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

Why are these marked readonly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe my thought process was that they should only be set by option providers, not manually, it would be fine to remove the readonly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should remove readonly to avoid unnecessary changes for anyone who may be touching the javascript apis.

@@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why wouldn't we want the owner to be nullable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Searching for .owner finds 161 uses, none of which handle nullable owners. In interest of avoiding more changes, I decided to leave it non-nullable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would setting the owner to itself be an alternative to using a symbol and needing to complicate the type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If Typescript allowed super(this), it would be. However since this isn't allowed, we either need to do super(undefined as any) and add the owner manually, or use a symbol.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, I'd like to double back on this, possibly at a later time to find a cleaner solution. For now it works.


/**
* The currently set type arguments.
*/
typeArguments: Type[];
typeArguments?: (Type | undefined)[];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is undefined allowed in the array?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like I missed this when cleaning up, there's no reason that it should be this way. Fixing.

const name = declaration.symbol.name;
if (this.typeArguments && this.typeArguments[index]) {
typeParameters[name] = this.typeArguments[index];
typeParameters[name] = this.typeArguments[index]!;
Copy link
Collaborator

Choose a reason for hiding this comment

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

that's annoying that this doesn't type automatically 😞

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does once typeArguments type is corrected to just Type[]

@@ -12,7 +12,7 @@ export function convertDefaultValue(node: ts.VariableDeclaration|ts.ParameterDec
if (node.initializer) {
return convertExpression(node.initializer);
} else {
return null;
return '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be undefined and the function signature be string | undefined

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, fixing.

src/lib/converter/nodes/accessor.ts Show resolved Hide resolved
@@ -29,7 +29,7 @@ export class ArrayConverter extends ConverterTypeComponent implements TypeConver
/**
* Convert the given array type node to its type reflection.
*
* This is a node based converter with no type equivalent.
* This is a node based convert er with no type equivalent.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo 😆

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops! Fixed.

}
});
return result;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was a good idea. 👍


/**
* A unique id that identifies this instance.
*/
private _listenId: string;
private _listenId!: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be _listenId?, as the uses on lines 408 and 415 check for null?

@@ -249,12 +254,12 @@ export class Event {
/**
* Has [[Event.stopPropagation]] been called?
*/
private _isPropagationStopped: boolean;
private _isPropagationStopped?: boolean;
Copy link
Contributor

@NaridaL NaridaL Oct 6, 2018

Choose a reason for hiding this comment

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

Why not just : boolean = false;?

Copy link
Collaborator

@aciccarello aciccarello left a comment

Choose a reason for hiding this comment

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

Was able to complete more review. Just a couple comments at this point. I'd like to get this large PR merged so it doesn't conflict with any other work. At some point in the futuer, I'd like to get rid of the Symbol designating the application but that can be done in a separate PR. Thanks for the hard work.

src/lib/utils/options/declaration.ts Show resolved Hide resolved
}

/**
* TODO: This should be a union type of multiple possible option types.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 This can be done later.

aciccarello and others added 10 commits October 12, 2018 08:19
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.
Copy link
Collaborator

@aciccarello aciccarello left a comment

Choose a reason for hiding this comment

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

Only change I'd like to see is removing the readonly's. Looking forward to merging this to master!

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

Choose a reason for hiding this comment

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

I think we should remove readonly to avoid unnecessary changes for anyone who may be touching the javascript apis.

@@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, I'd like to double back on this, possibly at a later time to find a cleaner solution. For now it works.

@Gerrit0
Copy link
Collaborator Author

Gerrit0 commented Oct 18, 2018

Not entirely sure why that build failed, there was no functional change made in the last commit. At least it also fails locally so I have something to go on...

@aciccarello
Copy link
Collaborator

Just on node 6? That's odd.

@Gerrit0
Copy link
Collaborator Author

Gerrit0 commented Oct 18, 2018

Yea, this is very odd. I had v9.10.0 on my machine, after upgrading to the 10.12.0, I get a different file causing the failure... Absolutely no clue where something broke.

@Gerrit0
Copy link
Collaborator Author

Gerrit0 commented Oct 19, 2018

Apparently highlight.js recently had an update which changed how language auto-detection works. The tests included some code blocks which did not specify a language, and so since the auto-detected language was different, highlight.js gave different output, causing a test failure.

Apparently npm 6.4.1 did not upgrade to the latest minor version (following package-lock.json) while npm 4.6.1 did. To resolve this, I pinned highlight.js to 9.12.0 which should have resolved the problem. I believe there may be a caching issue on the CI server as I was able to see all tests pass with node v6.14.4 and npm v4.6.1 locally.

@aciccarello
Copy link
Collaborator

Attempting to restart the CI

@aciccarello aciccarello reopened this Oct 19, 2018
@aciccarello aciccarello merged commit a2fab7c into TypeStrong:master Oct 20, 2018
@aciccarello
Copy link
Collaborator

@Gerrit0 Thanks for digging into that. That's frustrating that there was a change on a minor version...

@Gerrit0 Gerrit0 deleted the strict-null-checks branch October 20, 2018 04:38
mcaden added a commit to mcaden/typedoc that referenced this pull request Oct 24, 2018
This reverts commit a2fab7c.
Reverting to attempt to correct bug where flags not being written
christopherthielen added a commit to christopherthielen/typedoc-plugin-external-module-name that referenced this pull request Jan 9, 2019
@christopherthielen
Copy link
Contributor

christopherthielen commented Jan 10, 2019

Note that I had to switch to emitting es2015 in a typedoc plugin to support Typedoc 0.14.0. This is because typedoc classes are now emitted as ES6 classes and my plugin extends one of those classes. The plugin was emitting ES5 which uses _super.call(this), but you have to new an ES6 class.

@aciccarello
Copy link
Collaborator

👍 @christopherthielen Thanks for sharing that info. I'll update the release notes to communicate this.

@webmaster128
Copy link

Why does this pin highlight.js to 0.12.0?

The upgrade typedoc 0.13.x -> 0.14.1 now downgrades my highlight.js from 9.13.1 to 9.12.0.

@aciccarello
Copy link
Collaborator

It seems like hightligh.js made some changes to language auto-detection that changed tests and npm wasn't resolving consistently. @Gerrit0 could highlight.js be bumped and unpinned and the tests updated in a separate PR?

Apparently highlight.js recently had an update which changed how language auto-detection works. The tests included some code blocks which did not specify a language, and so since the auto-detected language was different, highlight.js gave different output, causing a test failure.

Apparently npm 6.4.1 did not upgrade to the latest minor version (following package-lock.json) while npm 4.6.1 did. To resolve this, I pinned highlight.js to 9.12.0 which should have resolved the problem. I believe there may be a caching issue on the CI server as I was able to see all tests pass with node v6.14.4 and npm v4.6.1 locally.

Gerrit0 added a commit that referenced this pull request Jan 11, 2019
aciccarello pushed a commit that referenced this pull request Jan 12, 2019
@aciccarello
Copy link
Collaborator

@webmaster128 Highlight.js has been updated on master and will be included in the next release.

christopherthielen added a commit to christopherthielen/typedoc-plugin-internal-external that referenced this pull request Jan 17, 2019
christopherthielen added a commit to christopherthielen/typedoc-plugin-ui-router that referenced this pull request Jan 17, 2019
trivikr added a commit to trivikr/aws-sdk-js-v3 that referenced this pull request Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants