-
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
Allow emitDeclaration
and isolatedModules
together
#29490
Comments
I am also looking for something similar. I will be using babel as a compiler via webpack for a monorepo, but still want features like project references for the editor experience in my monorepo and generating d.ts files for packages that are published. For my situation having a way to enforce the same limitations on language features that aren't supported by isolated modules without the restrictions on other typescript features would be ideal. I think that just means having an alternative way of treating usage of |
Why does this restriction currently exist? |
Everyone in the room is currently trying to figure out why this is a restriction. 😅 |
It looks like the restriction was there since the branch for The restriction was added (I think) in response to feedback which pointed out that Maybe the same restrictions need not apply for |
@RyanCavanaugh @SimenB proposed above allowing What else is required in order for this to be a full-fledged proposal? |
FYI, for anyone still reading this: The reason is for the same reason you can't use const enums in isolated modules: type information. Since isolated modules compiles each file individually without the types of the files it depends on, any inferred type we would write to a declaration file would potentially be incorrect, as their calculation would be missing information from the rest of the compilation. There is a limited subset of declaration emit where no types are inferred in the output which could be supported, however. |
Thanks Wesley! I understand now. What's recommended way for a user of babel-typescript to also generate declaration files? Something like the following?
@SimenB would that meet your needs as well? |
I'd have to run |
You should be able to specify a separate tsbuildinfo path for each build so they don't mangle one another's incremental data. |
@weswigham it doesn't seem like specifying the a separate tsbuildinfo path may not be necessary I'm seeing that the name of the tsconfig is automatically used as part of the name of the tsbuildinfo file. Given these tsconfigs: tsconfig.json {
"compilerOptions": {
"incremental": true,
"isolatedModules": true
}
} tsconfig-for-declarations.json {
"extends": "./tsconfig",
"compilerOptions": {
"emitDeclarationOnly": true,
"isolatedModules": false,
"declaration": true
}
} When I run both
|
@weswigham , you said:
Would this be the same limited subset that applies to TS files? If so, it seems like the restrictions would be worth it. Would implementing this change be a big effort or a small tweak? I know some people who may be interested in implementing. |
@weswigham checking in on this issue again. We'd really like to get the extra checks from --isolatedModules while also generating declaration files. Doing an extra pass would really slow down our pipeline. Is more information needed? Some question here. Thanks for your help with this issue. |
Pinging about this again. |
@sheetalkamat is this small enough? Is it a matter of just disabling the check? |
P.S. I'm going to assign you but if the issue is scoped enough, I'm going to encourage @mheiber to send a PR. |
@sheetalkamat , do you have guidance for us re:
If both are low/medium, we might be able to find someone who can contribute a fix. Thanks for your help. |
@mheiber @DanielRosenwasser and myself had discussion offline and it seems like the use case of what should be emitted in d.ts file is kind of vague. We are waiting on @RyanCavanaugh to be back to discuss this further to understand what .d.ts emit means, do we need to put some kind of restriction (eg specifying all types and nothing can be inferred) is still unclear. We also need to decide on what builder needs to do depending on outcome of I am removing mean while we would like to know why do you need to use |
@sheetalkamat thanks for looking into this and asking about our use cases. We're using isolatedModules because we want to be able to do separate compilation with ts.transpileModule in our Gulp pipeline. We use isolatedModules to verify that separate compilation is safe. Here are some of the specific reasons:
cc @robpalme: I think Rob may have more thoughts on why we're interested in --isolatedModules. |
thanks @sheetalkamat and team! |
Search Terms
isolated modules emit declaration
Suggestion
In the blog post introducing Babel 7, it's recommended to use
--isolatedModules
in the "Caveats" section (https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/).We use Babel to transpile our TS to better work with other tools in the ecosystem (such as Emotion or Jest), but we'd also still like to generate declaration files so consumers of our libraries can enjoy the type information.
However, when trying to follow the advice of adding
isolatedModules
to our config, we get the following warning:Use Cases
As mentioned, I'd like to create declaration files for libraries who are transpiled using
babel
. I'd also like to make sure that whatever guaranteesisolatedModules
adds to allowed syntax are present, outside of the type information.Babel itself will complain if we use e.g.
const enum
, but that only happens at compile time -isolatedModules
will also show a warning in the IDE while writing the code.Examples
Same as we currently get with
{"declaration": true, "emitDeclarationOnly": true}
, but with added{"isolatedModules": true}
.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: