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

Verify types.d.ts after generation #16703

Merged
merged 3 commits into from
Jun 17, 2022
Merged

Verify types.d.ts after generation #16703

merged 3 commits into from
Jun 17, 2022

Conversation

saschanaz
Copy link
Contributor

@saschanaz saschanaz commented Jun 16, 2022

Closes #16590

It seems it's even more broken since my report 😞

Oh, actually it's not that much broken, the initial error is from #16685 and reverting it makes it green.

@github-actions github-actions bot added the scripts Issues or pull requests regarding the scripts in scripts/. label Jun 16, 2022
Interestingly this does not make anything fail?
@github-actions github-actions bot added the schema Isses or pull requests regarding the JSON schema files used in this project. label Jun 16, 2022
@@ -262,7 +262,7 @@
"errorMessage": {
"additionalProperties": "Feature names can only contain alphanumerical characters or the following symbols: _-$@"
},
"tsType": "Record<string, Identifier> & {__compat?: CompatStatement};"
"tsType": "{[key: string]: Identifier} & {__compat?: CompatStatement};"
Copy link
Contributor

Choose a reason for hiding this comment

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

The TypeScript you're suggesting has broken imports of the data on Yari, because it's trying to map __compat to an Identifier type. Are you sure this is the right way to do this?

Copy link
Contributor Author

@saschanaz saschanaz Jun 16, 2022

Choose a reason for hiding this comment

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

This is just a manual definition of Record<string, Identifier>. It's semantically no different than Record<>, except it allows recursive reference. Note that this does not fail the test added by #16685.

Copy link
Contributor

@queengooborg queengooborg Jun 16, 2022

Choose a reason for hiding this comment

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

With this TypeScript type, however, we run into the following error on Yari:

Screen Shot 2022-06-16 at 15 34 11

The same issue occurs in a simplified test environment that uses the tsconfig.json from this project and includes an index.ts that just contains import bcd from "@mdn/browser-compat-data";.

The more I work with TypeScript, the more I hate it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried to build Yari but it's broken in another way 🤔

$ npm run build

> @mdn/[email protected] build
> cross-env NODE_ENV=production node build/cli.js

/mnt/c/Users/Kagami/Documents/GitHub/yari/node_modules/fdir/src/api/walker.js:48
  const needsSeperator = path[path.length - 1] !== sep;
                                   ^
builder/apiBuilder.js:18:10)
    at allDocumentPathsAsTree (/mnt/c/Users/Kagami/Documents/GitHub/yari/content/document-paths.js:20:23)
    at initAllDocumentsPathsTree (/mnt/c/Users/Kagami/Documents/GitHub/yari/content/document-paths.js:85:23)
    at Object.<anonymous> (/mnt/c/Users/Kagami/Documents/GitHub/yari/content/document-paths.js:95:33)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)

Node.js v18.1.0
npm notice
npm notice New minor version of npm available! 8.8.0 -> 8.12.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.12.2
npm notice Run npm install -g [email protected] to update!
npm notice

Copy link
Contributor

Choose a reason for hiding this comment

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

Good old code problems left and right... 🙃

I have a pull request open that uses an updated version of BCD (which includes the error I screenshotted up above), if you'd like to try mdn/yari#6490 out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(__compat! is probably not a real fix, but anyway)

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll want to check the logs in the "Testing Yari" CI test: https://github.com/mdn/yari/runs/6906221112?check_suite_focus=true

(I'm aware of the other two issues reported by the tests, I plan to fix those at a later time, once this issue is resolved!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I got what happened on Yari with your trial to fix:

image

It just made it to any, and that was hidden by skipLibCheck in Yari's tsconfig. 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, that makes sense -- so either way, it's broken...argh. This is honestly making me want to just give up on TypeScript altogether.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, I'm going to go ahead and merge this PR as-is with the reverted change, and then going to follow-up with updating the default TS export to cast to any first. I understand that's very bad to do and may result in unintended typecasts, but at this point, TypeScript users cannot use newer versions of BCD, including Yari.

@queengooborg queengooborg merged commit 3c21cb3 into mdn:main Jun 17, 2022
@saschanaz saschanaz deleted the exec-tsc branch June 17, 2022 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
schema Isses or pull requests regarding the JSON schema files used in this project. scripts Issues or pull requests regarding the scripts in scripts/.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unittest to validate TypeScript types
2 participants