-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Some typedefs are global and some aren't in --checkJs #15901
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
Comments
There are a few issues here. first second, a So a work around would be to move |
@mhegazy this does not seem to explain why adding /** @typedef {{[k: string]: any}} AnyEffect */
/** @type {AnyEffect} */
var a = {}; to Also, does TypeScript support exporting declarations from |
A much better workaround is to put your interfaces in a .d.ts file. There's no point in having a js file with nothing but comments, and if you use a .d.ts, then your package is ready for use from typescript if needed. |
That's not an ideal workaround because it seems the best pattern is to define interfaces in the file with the function that creates them. For instance, say I have a file: /** @typedef {isOn: boolean, timeLeft?: number} TimerState */
/** @return TimerState */
export function getTimerState() {...} Other files that use |
It's actually a better design to have TimerState in a separate file and then have both the implementer ( Disclaimer: I have been working on compilers for a long time, and maybe the best design for a compiler is different from other categories of software. |
I mean, I can understand the need for header files, which Honestly, though, not having header files at all is the current standard, at least my impression is that most modern code is written by just importing modules directly. |
I agree, this should work because it does work using typescript syntax in a typescript file. It's definitely a bug. I was just proposing a workaround to use until the bug is fixed. Not using header files is facilitated by classes, which declare a type and a value together. Maybe a better workaround for you would be to define a |
Fix is up at #16488 |
TypeScript Version: nightly (2.4.0-dev.20170516)
Code
These are excerpts that illustrate why it's weird:
dev-tools/globals.js
/** @typedef {{[k: string]: any}} AnyObject */
sim/dex-data.js
/** @typedef {{[k: string]: any}} AnyEffect */
sim/dex.js
tsconfig.json
These are excerpts that explain why this behavior is so weird, but the real reason why it works this way is probably in the rest of the code, which you can see for yourself in: https://github.com/Zarel/Pokemon-Showdown/tree/149ca3759c141085d2f473fc9fdc5da5371ef32c
Expected behavior:
No error, or perhaps two errors.
Actual behavior:
It's actually massively confusing to me how to access types defined in other files (I've googled and can't find any documentation on it). The general impression I get is that in modern TypeScript versions, in
.ts
files, you just export them and import them and they'll work normally, but still nothing on how to do it in.js
files.But either way, this seems like a bug.
(I tried moving the
AnyEffect
typedef fromsim/dex-data.js
todev-tools/globals.js
and I still get an error for it but notAnyObject
, so there is almost certainly something weird going on here.)The text was updated successfully, but these errors were encountered: