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.
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
Building TypeScript type definitions, along with some JSDoc #210
base: master
Are you sure you want to change the base?
Building TypeScript type definitions, along with some JSDoc #210
Changes from 9 commits
b627429
40bfd91
b400812
d7bc2fe
71d42ec
16a4a59
64aaa89
477f93f
2c73341
7523f53
81472fb
8eec9d5
4e3dc6a
a6476ff
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I'm sorta surprised this works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually because TypeScript treats
[]
asArray<undefined>
and forbids using it asArray<number>
. Probably usingArray.prototype.indexOf
is more understandable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? / is there some other decorator we could use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, TypeScript is called AnyScript for a reason - it fails to deduce that
str
has to beUint8Array
. An alternative is to make things more explicit:(One may also use
// @ts-expect-error
, but neither offers a way to specify the suppressed error type.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes the code harder to understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript does not track type info of the fields assigned only after object initialization. What about:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall that this caused problems in some ancient node version; or was it an issue with particular minifiers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to cause problems when there is a cyclic dependency: https://stackoverflow.com/questions/63371870/object-assignmodule-exports-vs-module-exports
Unfortunately,
loadlib.js
depending onfengari.js
creates exactly a dependency cycle. Maybe we can defer requiringfengari.js
(which is only used inside a library loading function)?(I just tried
Object.assign
and it turns out TypeScript empties all types definitions, leaving onlyexport {};
.)