Skip to content

Enable strict-mode for TypeScript#1783

Merged
fregante merged 124 commits intorefined-github:masterfrom
nickytonline:typescript-strict
Apr 17, 2019
Merged

Enable strict-mode for TypeScript#1783
fregante merged 124 commits intorefined-github:masterfrom
nickytonline:typescript-strict

Conversation

@nickytonline
Copy link
Copy Markdown
Contributor

@nickytonline nickytonline commented Feb 15, 2019

Basically going with the non-null assertion operator in almost all places, because as mentioned in #1735 (comment), the assumption with the extension is that the DOM nodes referenced in most cases are expected to be there. If they aren't, the extension breaks, a bug is filed and it's fixed.

One thing to note @bfred-it, is currently dom-chef types need to handle JSX (Element and IntrinsicElements) or we import @types/react.

Closes #1735

@sindresorhus sindresorhus changed the title Typescript strict Enable strict-mode for TypeScript Feb 15, 2019
@fregante
Copy link
Copy Markdown
Member

Uhm, apparently draft PRs aren't tested by Travis.

@nickytonline
Copy link
Copy Markdown
Contributor Author

nickytonline commented Feb 16, 2019

That's OK for now. I'm fixing all the strict errors, so the build would fail anyways. I'll undraft the PR once it's in a buildable state on my local.

@nickytonline
Copy link
Copy Markdown
Contributor Author

The changes are coming along well. The main hurdle I need to tackle is the types returned for JSX. In the context of dom-chef, we don't want the return type to be JSX types, we want it to be that particular element. e.g.

const button = <button>Hello</button>; // type returned should be HTMLButtonElement

@nickytonline
Copy link
Copy Markdown
Contributor Author

I'll get back on this in the next couple of days. Been under the weather a bit. 🤒

@nickytonline
Copy link
Copy Markdown
Contributor Author

@bfred-it @sindresorhus, we are green.

@nickytonline
Copy link
Copy Markdown
Contributor Author

nickytonline commented Apr 17, 2019

I think we're good here aside from another PR to put types that belong in their respective repos. Also, just want to make sure you're good with the WeakMap as suggested @bfred-it, https://github.com/sindresorhus/refined-github/pull/1783/files#diff-7f45906e508cad55f59cba1e4cf34ceaR13

@sindresorhus
Copy link
Copy Markdown
Member

@bfred-it I think we should merge this now if it doesn't break anything. We can continue commenting after merge and that can be fixed in a follow-up PR if there's anything.

@fregante
Copy link
Copy Markdown
Member

Let's test it out for a few hours and then I'll merge it (in ~10 hours?)

Copy link
Copy Markdown
Member

@fregante fregante left a comment

Choose a reason for hiding this comment

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

Just sorting out some compilation issues. I fixed the background entry point, but the options entry point still errors out when running npx tsc ./source/options.tsx.

npx tsc ./source/options.tsx 
node_modules/indent-textarea/index.d.ts:3:9 - error TS2502: 'watch' is referenced directly or indirectly in its own type annotation.

3     var watch: typeof watch;
          ~~~~~


Found 1 error.

From ... #1783 (comment)

Fixed in the latest indent-textarea. I saw this issue in many of my recent modules and they have all been fixed. https://github.com/bfred-it/indent-textarea/releases/tag/v1.0.4

</a>
);

const renderIcon = type === 'issue' ? stateIcons.issue[state as IssueNotificationState] : stateIcons['pull-request'][state];
Copy link
Copy Markdown
Member

@fregante fregante Apr 17, 2019

Choose a reason for hiding this comment

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

See ba30b4b

I prefer one line of dead code instead of lengthy types — same solution in another part of the same file: https://github.com/sindresorhus/refined-github/blob/cd741d368446f1d71877a00a74c84e84f9e488e3/source/features/mark-unread.tsx#L106-L114

const linkedSourceDom = Symbol('Attached RGH source dom');
const linkedRenderedDom = Symbol('Attached RGH rendered dom');
const rghButtons = new WeakMap<Symbol, Element>();
const rghButtons = new WeakMap<Element, Element>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in c0017d3

Details in commit

@fregante fregante merged commit 7b3b275 into refined-github:master Apr 17, 2019
@fregante
Copy link
Copy Markdown
Member

Two months in the making, probably the biggest PR in Refined GitHub 🗿

Great work @nickytonline!

@nickytonline nickytonline deleted the typescript-strict branch April 17, 2019 12:45
@sindresorhus
Copy link
Copy Markdown
Member

Amazing work, @nickytonline and @bfred-it

}

// TODO: Move types to the https://github.com/sindresorhus/linkify-issues repository.
declare module 'linkify-issues' {
Copy link
Copy Markdown
Member

@sindresorhus sindresorhus Apr 18, 2019

Choose a reason for hiding this comment

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

linkify-issues and linkify-urls now ship with their own TS types, so these can be removed.

Note that the repo option in linkify-issues was renamed to repository.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I'll remove the types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Related to Refined GitHub itself

Development

Successfully merging this pull request may close these issues.

Convert the whole codebase to TypeScript and make it strict

4 participants