Closed justinfagnani closed 7 years ago
I tried changing ./node_modules
and ./node_modules/@types
to typeRoots and caused a compiler crash. I'll file a separate bug for that.
Allow --declaration
with --allowJs
already tracked by #7546.
@j-oliveras thanks. Note that in this case I'm only using allowJs because tsc doesn't understand that these paths point to external packages.
why do you need --allowJs
?
@mhegazy because otherwise tsc won't let me import my dependencies:
import { dedupingMixin } from '../@polymer/polymer/lib/utils/mixin.js';
Produces this error:
src/poly-lit-element.ts(15,31): error TS6143: Module '../@polymer/polymer/lib/utils/mixin.js' was resolved to '/Users/justinfagnani/Projects/Polymer/polymer3/poly-lit/node_modules/@polymer/polymer/lib/utils/mixin.js', but '--allowJs' is not set.
The error is not correct. it should be only under --noImplicitAny
and it should not include --allowJs
as an option.. the whole issue is to tell the user that dedupingMixin
is implicitly given the type any
.
On a related note, where does the declaration of ../@polymer/polymer/lib/utils/mixin.js
live?
There is no declaration of ../@polymer/polymer/lib/utils/mixin.js
, it's plain JS coming from an npm package.
so you are fine with any
?
Yeah, I'll add a declaration then
TypeScript Version: 2.6.0-dev.20170909
Code
Background: I'm trying to use TypeScript for projects that work with native JS modules that are now supported in Safari and Chrome.
The project layout is like this:
My tsconfig.json is a little unusual, because I'm trying to set up multiple roots that include
/node_modules
and the advice of @mhegazy, in order to allow importing external packages by relative path (as required by web-compatible modules in the HTML spec):In /src/poly-lit-element.ts I import a file from another package via relative path:
Expected behavior:
The project compiles
Actual behavior:
Two sets of errors.
One is related to the project setup guessing the wrong source root, and not writing to to the ourDir as I configured it. Instead of writing files from /src/ to /, it's writing them next to their source. I think this is caused by allowJS change the source root detection when I import from other packages. Because of this with allowJS, tsc is trying to write out files from node_modules and complaining when they would overwrite their source:
And another set of errors that I can't use
allowJs
withdeclaration
:I'd really like to not turn on
allowJs
, but without it I can't import my dependencies.