Skip to content

TypeScript #15

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

Merged
merged 9 commits into from
Oct 18, 2019
Merged

TypeScript #15

merged 9 commits into from
Oct 18, 2019

Conversation

dgraham
Copy link
Contributor

@dgraham dgraham commented Oct 17, 2019

Converts the Flow + Babel toolchain to TypeScript.

The original motivation was to be able to use private instance variables without using the # syntax, but the private modifier is a compile-time only check. We need microsoft/TypeScript#30829 before we can replace our WeakMap state pattern with private fields.

There is no escaping the # syntax.

dgraham and others added 9 commits October 17, 2019 11:55
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
Co-authored-by: Mu-An Chiou <me@muanchiou.com>
@dgraham dgraham requested a review from a team October 17, 2019 20:01
super()
this.currentQuery = null
this.debounceInputChange = debounce(() => fetchResults(this))
this.boundFetchResults = () => fetchResults(this)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TypeScript's strict-property-initialization test caught these null instance variables previously assigned in the connectedCallback.

@@ -74,7 +81,7 @@ async function fetchResults(remoteInput: RemoteInputElement, checkCurrentQuery:
let errored = false
let html = ''
try {
response = await fetch(url, {
response = await fetch(url.toString(), {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch by TypeScript where the Fetch API doesn't accept URL values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interestingly, fetch does accept URL values, it just implicitly casts them to string: https://twitter.com/Keithamus/status/1185127977249574912

Copy link
Contributor

@keithamus keithamus left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@dgraham dgraham merged commit 9bf99a4 into master Oct 18, 2019
@dgraham dgraham deleted the typescript branch October 18, 2019 17:05
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