Open patarapolw opened 5 years ago
@patarapolw How does Reveal import into typescript? I tried it this way but it doesn't work for me:
import * as Reveal from 'reveal';
declare var Reveal: any;
can you help me please
@lliccien
Try this repo -- https://github.com/patarapolw/reveal-md/blob/c5721ded7aeaf60902b4c5b9b08aadc32317bfcf/web/src/lib/reveal-md.ts#L1
Basically, copy reveal-d.ts
to make it suit your needs.
I also need the typings... it makes not more sense if the creator of revealjs adds the typings to the original source repository? @hakimel please add it ;)
A response by the maintainer would be great here.
Is there already work done on 4.x types? Does the implementation of types need help by the community? Are types simply not intended for the project at all?
I am having the same problems, there is no way of getting it running when I import it in a TypeScript file that gets processed by Webpack with the Symfony Webpack Encore.
I only get it running when importing a second js file containing :
import Reveal from 'reveal.js';
import Markdown from 'reveal.js/plugin/markdown/markdown.esm.js';
import Highlight from 'reveal.js/plugin/highlight/highlight.esm';
let Reveal = new Reveal({
plugins: [
Markdown,
Highlight
],
hash: true
})
Reveal.initialize();
Unfortunately when trying to run this with Decktape is not working as typeof Reveal is always undefined ... I'll come back if I find a way to get this to work
@hakimel any update on how to use types? @types/reveal seem up-to-date but I found no way to get it to work so far; an official way to use them in the setup guide would be appreciated
If anyone wants to contribute types I'd be happy to merge. I don't have any experience with typescript so I'm probably not the right person for the job.
Usually, if @types is not available, the following method is used.
// revealjs.d.ts
declare module 'reveal.js' {
// Please define this content https://www.npmjs.com/package/@types/reveal
}
The best easy way for other people, is someone has to make a Pull Request to https://github.com/DefinitelyTyped/DefinitelyTyped
If the PR is somehow accepted, it will automatically (automated) create @types/reveal.js
; and yeah, the name must match reveal.js
, that is, if you install reveal.js
from NPM.
There is also another way. reveal.js.d.ts
is included inside reveal.js
's NPM, and there is this in package.json
{
"types": "reveal.js.d.ts"
}
I made a pull request (#/62110) to @types/reveal
. I updated types according to the latest api.
As I set reveal.js
as module (suggested https://github.com/hakimel/reveal.js/issues/2496#issuecomment-1026608148), you can use type hints of reveal.js
if you install @types/reveal.js
.
EDIT
@types/reveal.js
has been merged (#/62110). From now on you can install this package to use typescript.
I'm having a slight issue with the types for plugins.
For example, the highlight plugin's path is
/plugin/highlight/highlight.js
But the type definition's path is
/plugin/highlight/highlight/index.d.ts
This doesn't work when the files are imported with the .js
file extension. It would be preferable if the type definition was at
/plugin/highlight/highlight.d.ts
The other plugins are the same.
I am interested in using Reveal.js in an SPA in TypeScript, so I created
index.d.ts
. I do have problem with some typings, though. Basically, anything that get marked as any, for examplefunction getSlide(x: any, y: any): HTMLElement;
function registerPlugin(id: string, plugin: any): void;
function addKeyBinding(binding: any, callback: () => void): void;
There is @types/reveal, but it is probably deprecated.