hakimel / reveal.js

The HTML Presentation Framework
https://revealjs.com
MIT License
67.92k stars 16.65k forks source link

@types/reveal.js #2496

Open patarapolw opened 5 years ago

patarapolw commented 5 years ago

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 example

There is @types/reveal, but it is probably deprecated.

lliccien commented 4 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

patarapolw commented 4 years ago

@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.

SvenBudak commented 4 years ago

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 ;)

DerMolly commented 4 years ago

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?

DennisdeBest commented 4 years ago

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

BlueskyFR commented 2 years ago

@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

hakimel commented 2 years ago

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.

sin-to-jin commented 2 years ago

Usually, if @types is not available, the following method is used.

  1. Putting this file 'revealjs.d.ts' to /types directory
// revealjs.d.ts
declare module 'reveal.js' {
  // Please define this content https://www.npmjs.com/package/@types/reveal
}
  1. Adding the filepath to tsconfig.json
patarapolw commented 2 years ago

The best easy way for other people, is someone has to make a Pull Request to https://github.com/DefinitelyTyped/DefinitelyTyped

image

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"
}
keitaninja commented 2 years ago

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.

lkarabeg commented 1 year ago

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.