-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Generating Type Definitions from Javascript is blocked by requiring private name #37832
Comments
This is broken in 3.8 and 3.9 at least. |
@sandersn thank you kindly for the quick triage. This is a bit of a roadblock for our migration to TypeScript, would it be helpful if we tried to fix this locally? Or is there already someone on your end that will begin work shortly? |
From talking to @weswigham about a similar issue (probably the same issue), it's an unfortunate limitation in the way that we bind declare const _tmp: { Thing: Thing }
export = _tmp It's probably possible to special-case this exact pattern and emit @mbroadst I put this in 4.0 assuming that the real fix would be complex. |
@sandersn you have it exactly. |
Unfortunately this is useless right now because typescript does not generate the types correctly yet. We have to wait for typescript >= 4.0 See microsoft/TypeScript#37832
Is there a workaround for this to prevent the CLI from erroring? I tried |
@nbbeeken Try to |
I appreciate the help! unfortunately that doesn't seem to work. The goal is to generate types from jsDoc comments so tsc needs to allow .js files as input. Here's the errors you get if allowJs is false: (setting checkJs to false just removes the TS5052 error)
|
I am having the same error message without using explicit exports (tested with TypeScript 3.9.7). Sadly, some files produce an error that cannot be ignored: Minimal example:
The error message is somewhat brittle. In this toy example it goes away when adding constructors to the two Bla implementations. |
@nbbeeken, I had a case somewhat similar to yours, where our app was exporting a function that set a property (which I think TypeScript recognizes as a constructor): module.exports = function(key) {
const myImpl = implementations[key];
this.invoke = myImpl.invoke;
}; and it was throwing this error: By changing |
Thanks for the suggestion @jrnail23!
Here's a quick screenshot to show I'm using the example in the issue description. |
Came to this issue because I was getting the same error, even when I had |
Yep, this is fixed in 4.1 -- although I found a related bug when |
```js const x = require('./foo').y ``` was incorrectly using the unmangled require path as the temp name in emit: ``` import ./foo_1 = require('./foo') import x = ./foo_1.y ``` It now uses the imported identifier: ``` import x_1 = require('./foo') import x = x_1.y ``` Discovered while fixing #37832
```js const x = require('./foo').y ``` was incorrectly using the unmangled require path as the temp name in emit: ``` import ./foo_1 = require('./foo') import x = ./foo_1.y ``` It now uses the imported identifier: ``` import x_1 = require('./foo') import x = x_1.y ``` Discovered while fixing #37832
Are you sure this is fixed in 4.1?
I have the same problem both on 4.0.3 and 4.1, not sure is the exact same problem, minimal example included here: ... maybe I did something wrong? Should I open a new ticket with the code I posted in stackoverflow? |
re-exporting classes now leads to tsc crash "Unhandled alias declaration kind in symbol serializer!" Additionally, this bug still persist, see this repro: When trying to avoid the above crash, i've set the imported class to an intermediate variable, and exported it. |
@sandersn @weswigham – Can this issue be reopened? I get the following when trying to generate definitions for stylelint (using TS
|
@glen-84 can you please share a minimal repro? |
@glen-84 While the error is the same, it's not the same issue, What we are missing there to make it nicer is a way to Also: seems like you are depending there on types from |
So this is triggered by the use of Do you know if there is an existing GitHub issue for this?
Where do you see that? (note: I am not a maintainer of stylelint) |
I believe something like that
I think not
Example: |
Okay, I'll probably open one.
This resolves to the local types in the |
I'de say to relocate them, and import them as regular source files, and not like so (It will break if you publish) |
Here is a minimal example, less than 20 lines in total, it gives the error of this bug both on typescript 4.0 that on 4.1 beta: https://github.com/ggreco/doc2dec
|
@ggreco Will you create a new issue? |
Ugly workaround: |
This is fixed in latest //// [lib.d.ts]
/**
* @param {string} a
*/
export function bar(a: string): string;
export class SomeClass {
a(): number;
}
//// [main.d.ts]
export const IntermediateClass: typeof SomeClass;
import { SomeClass } from "./lib"; If anyone comes back to this thread using latest nightly TS and thinks they have "the same bug" - please open a new thread with your repro - tracking stuff in closed issues is hard - thanks~ |
I used |
…hwierig dabei war der Dies war schwierig dabei war share.js da dort ein TyperScript Kompilierfehler ohne Zeilenangabe auftrat. Dieser war auf ein Bug in TypeScript zurückzuführen konnte durch eine @type JSDocs annotation behoben werden. Siehe microsoft/TypeScript#37832 welches obwohl es als geschlossen wurde immer noch auftritt.
Edit: Posting here as I don't have a reduced reproducing example yet but wanted to share until I have one.
I am seeing a similar error message in TypeScript 4.3.2 with the following pattern: /* data_listener.js */
export function createDataListener() {
return async function dataListener(someObj, x, y) {
// `this` references the model instance
this.blah = something;
};
}
/* create.js */
import {createDataListener} from "../data_listener";
someObj.setDataListener(createDataListener().bind(model, someObj)); I tried removing the /* data_listener.js */
export function createDataListener() {
return async function dataListener(model, someObj, x, y) {
model.blah = something;
};
}
/* create.js */
import {createDataListener} from "../data_listener";
someObj.setDataListener(createDataListener().bind(undefined, model, someObj)); |
Not sure how to default export from JSDoc-powered JS, when in CommonJS. Once I move to ESM and or TS it's not an issue, but I was kind of surprised that this didn't work already, since it's an existing practice for Node packages that have been around for a while. I'm probably just doing it wrong, but I'm not totally sure. I thought it might've been the part where it was assigning both the variable and the `module.exports` in the same line, but that didn't fix the errors either. microsoft/TypeScript#37832 https://stackoverflow.com/questions/60009092/declaration-will-not-emit-due-to-private-name-usage microsoft/TypeScript#2719 Super bowl!!!!! aaaeaaeggh, 380 green hut, AA
TypeScript Version: 3.9.0-dev.20200407
Search Terms:
Code
tsconfig.json:
Expected behavior:
I believe I should get two declaration files out of this that would look something like:
Actual behavior:
index.d.ts
fails to be emitted with the error:It's not clear to me how to annotate the module.exports to make the "name" not private anymore
Thanks for taking a look.
Playground Link: Can't because imports related but I made a minimum repro here: https://github.com/nbbeeken/private-name-error-tsc
Related Issues: #9865
The text was updated successfully, but these errors were encountered: