Add create-react-app and puppeteer user tests #23471
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds create-react-app and puppeteer to the user tests. I'm tracking the amount of work that would be needed to add a tsconfig to these projects with checkJs turned on.
create-react-app
create-react-app is a facebook package, so it requires yarn and a couple of subprojects are written in flow.
Errors
require
a json file.url.parse
returns an object withhostname
defined before usinghostname
.Promise.reject
requires one parameter, a reason.fs.readFileSync
returns a Buffer, not a string, with no encoding specified. Node's d.ts has aJSON.parse
that doesn't accept Buffers, even though it usually works.process.env["NODE_ENV"]
is defined before using it index into an object.fs.F_OK
, justfs.constants.F_OK
. The former isn't documented.checkRequiredFiles
, we markcurrentFilePath
as use-before-defined because control flow doesn't understand that it will only ever be used if the body of the for loop executes and then throws after an initial assignment.execSync
because theencoding: 'utf8'
field of an object literal that's assigned to a variable widens toencoding: string
.window
as the global type, which containsencodeURIComponent
. Should be fixed when we introduce a global type.Test changes
Fixes
fs.accessSync
can throw, and thatcurrentFilePath
is always assigned in this case.module
is pretty difficult and probably not worth it now.Result
Once things are up and running, the outcome is solid. Typescript catches 4 lint-y errors (3, 5, 6, 8) and 2 bugs-waiting-to-happen (4, 7). The other 6 are covered above. 50% is an acceptable ratio, I think.
Still, getting create-react-app to work would require some expertise to avoid chalk errors and to realise that flow errors were blocking semantic errors. After that, one error stands out as hard to fix: literal widening, which requires the author to know the closure type cast syntax (
/** @type {'utf8'} */('utf8')
).I posted a stack overflow question to help people learn how to override bad types that ship with a package.
puppeteer
puppeteer is a google package that already uses typescript. I think it was ported from closure, because lots of the types use the
!
-prefix, which does nothing in typescript.Errors
Types in the namespace
Protocol
are not found. I look around and could not find these either. That's it.Fixes
In general, resolving types in closure-originating code is difficult. We could do better. Since I couldn't find the namespace
Protocol
myself, I can't propose any new ones this time.Result
puppeteer already uses checkJs, so all the work has already been done.