-
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
Declaring typings for modules in subfolders #17945
Comments
Hi @mhegazy I believe you're referencing the pre-beta (0.18) definitions on I think @sebald is trying to provide a newer definition inside the beta npm package |
do you have a self contained repro i can look at? |
@mhegazy Sure, here you go: https://github.com/sebald/mui-typings-error You can find the issue here: I tried to resolve the issue yesterday by structuring the typings differently, but had no luck. Basically, importing from the "root" module works: // tslint:disable:max-line-length
import * as React from 'react';
- import Button from 'material-ui/Button/Button';
+ import { Button } from 'material-ui';
const App = () => <Button>Click me!</Button>;
export default App; My guess is that TS is using the (correct) modules resolution inside the As said, moving the exact same file to |
I think i understand the issue, but let me restate it to make sure we are on the same page.
if this is accurate, then the behavior your seeing is what i would expect.
Having said that, i would recommend against putting types in global space. global space declarations do conflict if there are multiple of them (e.g. multiple version of material-ui due to transitive dependencies), and the compiler will error in these cases. Modules on the other hand have their own scope, so you can have multiple versions of a module co-existing side by-side. so you are doing your users a favor by having your files organized as modules. Hope that helps. |
Thanks again for your detailed answer! I was a bit confused why TS handles local and typings inside
What do you mean by "no file with that name". The actual implementation exists on the corresponding paths. Meaning there is an So, in order to don't have them in the global scope (which is also done when using
I thought that publishing the types with the npm package is the preferd solution. As a consumer of mostly non-TS libs I fully support this, especially because the typings actually match the library and are not out of date. Also, having The v1 of |
there is .d.ts/.ts/.tsx file
yes. what i said before does not contradict with this statement.
The only thing special about
I see there are .flow files in each folder, seems reasonable to allow a .d.ts as well.. I think the best work around at the moment, is to ask users to add |
Thank you so much for your help! Even though I don't like to have users add Again. Thanks! Really appreciate it \o/ I am closing this, since from my side everything is resolved. |
TypeScript Version: 2.4.2
Code
Full source can be found here
Expected behavior: Defining all modules exported by a npm-module (including sub-modules, like
material-ui/Button/Button/
) will allow the developer to import not only the root but also the sub-modules.Actual behavior: TypeScript seems not to pick up sub-modules defined in the "root"
index.d.ts
, when a module other than the rootmaterial-ui
is used and expects anindex.d.ts
/typings definition inside the corresponding folder.This behavior only occurs if the typings are used inside an npm-module. Using the (linked) typigns locally or inside
@types/material-ui
works fine.The text was updated successfully, but these errors were encountered: