-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
[Question] Can't have a "pure" typescript library. #5225
Comments
that is not correct. the .d.ts file is only needed if you do not have a .ts file, as a matter of fact, the compiler, when resolving |
@mhegazy my import looks like |
so how are you building the JS file for this node module? |
@mhegazy the library |
but your module |
@mhegazy I'm building my app with webpack and https://github.com/s-panferov/awesome-typescript-loader or https://github.com/TypeStrong/ts-loader. These tools don't need any Everything works correct, but Webpack's workflow is very convenient:
I know that this workflow is slower because we need to recompile files every time, but tools like I suggest to make a compiler flag that allows to require raw |
thanks for the explanation. keep in mind that importing a .ts has some results: the file, and all its dependencies will be brought into your compilation, this can show you errors from other components, will slow down your compilation and will add global declarations from these files into your global namespace. |
@mhegazy yes, I understand this consequences.
This is what we want in 90% cases. E.g. we have a library with React components,
And it's all we need to add a Button and it's dependencies to the project and type-check everything. If we need to import only a compile-time type (e.g. interface) from a module, TypeScript does not emit
All our modules are pure |
PR #4911 should remove this restriction. |
One still can't have "pure typescript library" until #5278 gets resolved, am I right? Now getting an error "…can only be in .d.ts files…" on the nightlies. @s-panferov, thanks for bringing this up. Strange that discussion started only 2 weeks ago, like nobody else is using similar workflows. |
Hello. Sorry if this issue is a double (I can't find anything relevant). Out team uses TypeScript for frontend development and we are trying to use TypeScript everywhere. So we have several libraries written fully in TypeScript.
If I understand correctly, we can't make simple
import { smth } from 'pure-ts-lib/some-module';
work without having a generatedsome-module.d.ts
file nearsome-module.ts
. It's very inconvenient to us, because it adds an extra compilation step and more files we need to track. Is there a chance to change this behaviour to simply resolve a.ts
module if any? Maybe we can control it by a compiler flag?References:
TypeStrong/atom-typescript#560 (comment)
https://github.com/Microsoft/TypeScript/blob/master/src/compiler/program.ts#L130
The text was updated successfully, but these errors were encountered: