typescript - Typings for sub-folders inside a root index.d.ts -
we created typings material-ui@next
, want ship them library, did last beta.
here link index.d.ts
.
but typings not usable in current form. in development used locally , worked fine, when shipping files library typescript seems use different discovery strategy.
all typings reference subfolder (e.g. declare 'material-ui/button/button'
) not found typescript. when importing components error show up:
[ts] not find declaration file module 'material-ui/button/button'. '<project path>/node_modules/material-ui/button/button.js' implicitly has 'any' type. try `npm install @types/material-ui/button/button` if exists or add new declaration (.d.ts) file containing `declare module 'material-ui/button/button';`
does typescript not accept declaring other imports when used inside npm_modules
folder? because said, using them locally or moving them @types/material-ui
make them work.
also, typescript seems find index.d.ts
, because importing "root" works (import { button} 'material-ui'
).
so, turns out typescript treats typings inside of node_modules/@types/*
, node_modules/*
different:
typings in @types
called augmented modules. global , in them on project's code. why accessing submodule declarations, material-ui/button/button
, work.
regular npm modules treated (regular) modules. thus, if import subfolder subfolder must contain typings. typescript not go root of modules , check if typings there have augmented modules.
this means (a) have publish typings definitelytyped
or created .d.ts
files every subfolder , file.
you can find longer explanation here: https://github.com/microsoft/typescript/issues/17945
wiki
Comments
Post a Comment