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

Update to TypeScript 2.2.1 #448

Merged
merged 5 commits into from
Mar 15, 2017
Merged

Conversation

devpaul
Copy link
Contributor

@devpaul devpaul commented Mar 14, 2017

  • updated node engine to 4.2.0+ to match TypeScript's
  • optionDeclarations.type can now be a Map added support to declaration
  • tsconfig to include es2015 collections lib

Will resolve #432, #414, and #417; maybe #344

tsconfig.json Outdated
"lib": [
"DOM",
"ES5",
"ScriptHost",
Copy link
Member

Choose a reason for hiding this comment

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

What is ScriptHost used for?

Copy link
Contributor Author

@devpaul devpaul Mar 14, 2017

Choose a reason for hiding this comment

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

It's a standard include w/ an ES5 target. It's possible we don't need it, but I am not familiar enough to remove a prior dependency.

https://github.com/Microsoft/TypeScript/blob/master/lib/lib.scripthost.d.ts

Copy link
Member

Choose a reason for hiding this comment

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

No it's not. That looks like IE-specific extensions and definitely isn't ES spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It is mostly IE-specific extensions. It's not part of the ES spec. It is included when --target: ES5 (and ES6) is used. See https://www.typescriptlang.org/docs/handbook/compiler-options.html under the --lib row.

Note: If --lib is not specified a default library is injected. The default library injected is:
► For --target ES5: DOM,ES5,ScriptHost

Anyway, I removed ScriptHost locally and it compiled. Ambient declarations from definitely typed don't typically reference it, so we should be OK removing it.

Copy link
Member

Choose a reason for hiding this comment

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

What references is irrelevant here - we shouldn't be including any libraries we don't have. We shouldn't even include dom since we're not in the DOM. All that does is give a false sense of security and errors at runtime instead.

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 that if lib is not specified in tsconfig.json, then dom is part of the default libs brought in per https://www.typescriptlang.org/docs/handbook/compiler-options.html and DOM is necessary in this project because highlight.js is a dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing DOM fails the build:

Running "ts:typedoc" (ts) task
Compiling...
Using tsc v2.2.1
node_modules/@types/highlight.js/index.d.ts(19,40): error TS2304: Cannot find name 'Node'.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's a known issue with highlight.js - I believe we've mentioned it somewhere - maybe wherever we moved to @types. Fixing that is sadly contingent on fixing the definition in DefinitelyTyped or enable TypeScript to understand browser resolution/do conditional definition paths (since there's no Node constructor in node).

@@ -46,7 +46,7 @@ export class OptionDeclaration {

scope: ParameterScope;

map: Object;
protected map: Object | Map<string, string> | 'object';
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid the protected change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Limiting the scope made it easier to understand where map is being used. Is there a reason to keep this value public?

Copy link
Member

Choose a reason for hiding this comment

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

Yes - if someone is using it, you just broke them. Backward compatibility is important, even though it's minor. In any case, they'll probably break anyway since the type has changed, but this is really just an unnecessary change as a result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

map is really an internal implementation detail of what OptionDeclaration does and shouldn't be public. If map remains public then anyone who relies on map will silently fail; because Map is also an Object TypeScript will not throw an error about incompatible types and map will look like an empty object. Changing map to protected ensures anyone who wants to continue to use map will need to extend this class and be aware of the change. Overall, we are better off making this breaking change and preventing silent failures for users.

const key = value ? (value + '').toLowerCase() : '';
try {
this.getMapValue(key);
} catch (error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we please avoid using try..catch statements here. It seems like we should be able to keep most of the code the same as it was instead of changing all this.

Copy link
Member

Choose a reason for hiding this comment

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

I don't actually see where you'd updating value = anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I can make this change.

errorCallback('Invalid value for option "%s".', this.name);
}
const message = this.mapError ? [this.mapError] : ['Invalid value for option "%s".', this.name];
errorCallback(... message);
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep this code the same as it was before, I don't think there's any need to be clever here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants