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

Allow default imports in TS #200

Merged
merged 1 commit into from
Jul 23, 2020

Conversation

danvk
Copy link
Contributor

@danvk danvk commented Jul 21, 2020

This makes the ES6 version of the example on the homepage work:

import xss from "xss";
const html = xss('<script>alert("xss");</script>');
console.log(html);

Note that this only works if esModuleInterop is set to true, which is officially recommended (tsc init produces a tsconfig.json file with it set). You can read more about it here.

The existing type tests seemed to be broken before this PR:

$ npm install typescript
$ tsc --version
Version 3.9.7
$ tsc --noEmit -p typings/tsconfig.json
typings/xss-tests.ts:9:22 - error TS2307: Cannot find module 'xss' or its corresponding type declarations.

9 import * as xss from "xss";
                       ~~~~~

typings/xss-tests.ts:30:14 - error TS7006: Parameter 'str' implicitly has an 'any' type.

30   escapeHtml(str) {
                ~~~

typings/xss-tests.ts:34:9 - error TS7006: Parameter 'tag' implicitly has an 'any' type.

34   onTag(tag, html, options) {
           ~~~

typings/xss-tests.ts:34:14 - error TS7006: Parameter 'html' implicitly has an 'any' type.

34   onTag(tag, html, options) {
                ~~~~

typings/xss-tests.ts:34:20 - error TS7006: Parameter 'options' implicitly has an 'any' type.

34   onTag(tag, html, options) {
                      ~~~~~~~

typings/xss-tests.ts:37:15 - error TS7006: Parameter 'tag' implicitly has an 'any' type.

37   onIgnoreTag(tag, html) {}
                 ~~~

typings/xss-tests.ts:37:20 - error TS7006: Parameter 'html' implicitly has an 'any' type.

37   onIgnoreTag(tag, html) {}
                      ~~~~


Found 7 errors.

After it they are not:

$ tsc -p typings/tsconfig.json

@danvk danvk force-pushed the typescript-default-import branch from ec82735 to d852c67 Compare July 21, 2020 21:20
@danvk danvk marked this pull request as ready for review July 22, 2020 15:34
@danvk
Copy link
Contributor Author

danvk commented Jul 22, 2020

The PR Quality Review check is about adding a console.log in a test file:

image

This is done in other test files as well

console.log(a.onIgnoreTag, a.remove);
console.log(xss.filterXSS("hello"));
console.log(

continuous-integration/travis-ci/pr is also broken on master.

@leizongmin leizongmin merged commit 32abe71 into leizongmin:master Jul 23, 2020
@leizongmin
Copy link
Owner

Thank you. This change will be included in the next release version.

@leizongmin
Copy link
Owner

I just published a new version xss@1.0.8 including this changes. Thanks for your pull request.

@danvk
Copy link
Contributor Author

danvk commented Jul 28, 2020

Thanks for the quick release, @leizongmin! I merged this update into my project and it works great.

leizongmin added a commit that referenced this pull request May 6, 2021
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.

2 participants