symfony / stimulus-bridge

Stimulus integration bridge for Symfony projects
https://symfony.com/ux
75 stars 15 forks source link

TypeScript Declarations #7

Closed chapterjason closed 3 years ago

chapterjason commented 3 years ago

Hey,

type declarations would be nice, cause after activating typescript in webpack encore the console outputs something like this; a bit annoying:

 ERROR  Failed to compile with 1 errors                                                                                                                                                 9:03:45 PM

 error  in /[...]/assets/bootstrap.ts

[tsl] ERROR in /[...]/assets/bootstrap.ts(1,34)
      TS7016: Could not find a declaration file for module '@symfony/stimulus-bridge'. '/[...]/node_modules/@symfony/stimulus-bridge/dist/index.js' implicitly has an 'any' type.

Cause its only one function that is exported something like this should work:

declare module "@symfony/stimulus-bridge" {
    import { Application } from "stimulus";

   // Actually stimulus serves its own types, but for the webpack context https://www.npmjs.com/package/@types/webpack-env is required.
    export function startStimulusApp(context: __WebpackModuleApi.RequireContext): Application;
}

You can use this as a workaround. IIRC: For usage as implementation the declare module is not required, just the types reference in the package.json to the index.d.ts or similar file.

Cheers!

tgalopin commented 3 years ago

I saw your PR, thanks, that's a good idea indeed!