Skip to content

Enable strict-mode for TypeScript - #1783

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

fregante merged 124 commits into
refined-github:masterfrom
nickytonline:typescript-strict

Conversation

@nickytonline

@nickytonline nickytonline commented Feb 15, 2019 •

Copy link
Copy Markdown
Contributor

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

Comment thread source/features/add-co-authored-by.tsx Resolved
Comment thread package.json Resolved
Comment thread source/globals.d.ts Resolved
Comment thread source/libs/get-default-branch.ts Resolved
Comment thread source/libs/group-buttons.tsx Resolved
Comment thread tsconfig.json Resolved
Comment thread tsconfig.json Resolved
@sindresorhus sindresorhus changed the title Typescript strict Enable strict-mode for TypeScript Feb 15, 2019
Comment thread source/features/add-co-authored-by.tsx Resolved
Comment thread tsconfig.json Resolved
Comment thread tsconfig.json Resolved
@fregante

Copy link
Copy Markdown
Member

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

@nickytonline

nickytonline commented Feb 16, 2019 •

Copy link
Copy Markdown
Contributor Author

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.

Comment thread source/globals.d.ts Resolved
@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. 🤒

Comment thread package.json Resolved
Comment thread source/features/mark-unread.tsx Resolved
Comment thread source/features/mark-unread.tsx Resolved
Comment thread source/features/mark-unread.tsx Resolved
Comment thread package.json Resolved
Comment thread source/features/batch-open-issues.tsx Resolved
@nickytonline

Copy link
Copy Markdown
Contributor Author

@bfred-it @sindresorhus, we are green.

@nickytonline

nickytonline commented Apr 17, 2019 •

Copy link
Copy Markdown
Contributor Author

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?)

@fregante fregante left a comment

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.

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

Comment thread source/globals.d.ts Resolved
Comment thread source/features/mark-unread.tsx Outdated
</a>
);

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

@fregante fregante Apr 17, 2019 •

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.

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 ✨

Comment thread source/globals.d.ts
}

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

@sindresorhus sindresorhus Apr 18, 2019 •

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.

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