madskristensen / TypeScriptDefinitionGenerator

A Visual Studio extension
Other
85 stars 46 forks source link

How do I consume these definitions? #39

Closed phrei closed 2 years ago

phrei commented 6 years ago

Installed product versions

Description

I cannot consume the generated types. I've tried ///referenc'ing it and I've tried it with "import { server } from '../../MyType.cs.d.ts'" (here it tells me, that MyType.cs.d.ts ist not a Module!) - with no success.

If I change "declare" to "export", the import seems to work fine but I cannot use the type with server.MyType.

A short description in your ReadMe on how to consume the files would help a lot.

denis-peshkov commented 6 years ago

Hi @phrei, I have the same problem, so as I understood it is possible to use modules and namespaces only with node. So for now I have a project on React app and have to use it, but can't.

I'm working on this solution, so you can find my latest version on the fork of this repository.

p.s. guys, if any ideas how to use modules/namespaces in React inform me please.

denis-peshkov commented 6 years ago

As I understood this .d.ts files should be used only as DefinitelyTyped (https://github.com/DefinitelyTyped/DefinitelyTyped) for creation module (http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html),

but in most cases we have use it as a standard module of TS (like http://www.typescriptlang.org/docs/handbook/modules.html)

Any comments?

denis-peshkov commented 6 years ago

I found out an answer in https://stackoverflow.com/questions/41749581/why-is-declare-word-used-in-the-d-ts-files?rq=1.

So, the .d.ts files required only for telling to TypeScript that the class/interface/enum has been created elsewhere. By the way, you need to implement it somewhere. Otherwise you can to describe a variable that you get from API request, or describe as in function variable.

That's why I can't see the need to use it. Instead of I propose just use export and import.