Skip to content

Move "types" into the package #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2022

Conversation

weaverryan
Copy link
Member

Fixes #39

Instead of having a separate @symfony/stimulus-bridge-types package, it's easier (both for us but mostly for users) to embed it directly in the package.

Cheers!

This was referenced Dec 7, 2021
@chapterjason
Copy link
Contributor

chapterjason commented Dec 7, 2021

Hey :)

  1. The package.json file in the types folder can be removed and we should mark it as deprecated on npm (never had the case before)
  2. The types file should now look like this if it is served with the source:
/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import { Application } from "@hotwired/stimulus";

export declare function startStimulusApp(context?: __WebpackModuleApi.RequireContext): Application;
  1. As in my first proposal in Add typescript types #8 we will have the issue that types for __WebpackModuleApi.RequireContext will be missing. Adding @types/webpack-env as dependency will fix that.

@tgalopin
Copy link
Contributor

tgalopin commented Dec 9, 2021

Would it make sense to write this whole package in Typescript too, which would avoid the need for a types file?

@chapterjason
Copy link
Contributor

chapterjason commented Dec 9, 2021

@tgalopin I proposed that for encore some months/years ago.

The drawback is that you can't test dev branches, as you need to compile first. Can't find the comment anymore. Or you need to check in the dist (what is already the case, what I would prefer to get rid of.)

I think for now it is enough to have just the types, the package is pretty small for that overhead.

found the comment: symfony/webpack-encore#816 (comment)

/edit I'am confused, just checked the source, and it is already ts. 😄 What we could do is, set this to true

"declaration": false,

and reference the output .d.ts in the package.json instead.

/edit Also this can be typed

export function startStimulusApp(context: any) {
as __WebpackModuleApi.RequireContext from @types/webpack-env

@tgalopin
Copy link
Contributor

tgalopin commented Dec 9, 2021

Ah right, I mixed things up, this package is already TS. Let's finalize this PR then!

@weaverryan
Copy link
Member Author

When I output all of the .d.ts files locally, it creates (of course ) .d.ts files or ALL of the files. Do we want to do that? Really, only the startStimulusApp is something the user should want the type for. WDYT?

@chapterjason
Copy link
Contributor

I wouldn't maintain the types separately.

IIRC with { "types": "./dist/index.d.ts" } the consumer only get types for exports defined in the given file. So it wouldn't affect the consuming tsc or ide.

image

You only get the other types if you explicit import them like that:

image

@dehy
Copy link

dehy commented Apr 5, 2022

Any news about this PR ? Having the types inside the package would be great.

@weaverryan weaverryan force-pushed the types-in-package branch 2 times, most recently from 33c8c96 to 76f8a63 Compare April 20, 2022 15:21
@weaverryan
Copy link
Member Author

@chapterjason can you have a look now?

The only weird part is that, while you can build the types with yarn tsc, it will also output .d.ts files for files like dist/util/get-stimulus-comment-options.d.ts, which is not a file we actually build into the dist/ folder. For now, I've just manually not included those extra files.

@chapterjason
Copy link
Contributor

@weaverryan LGTM

In the end it's just javascript and the method is theoretically still loadable and useable. If you import @symfony/stimulus-bridge/util/get-stimulus-comment-options you don't have types. But I think it's fine to ignore it, cause it isn't part of the public API.

@chapterjason
Copy link
Contributor

chapterjason commented Apr 20, 2022

Ahh I forgot, we also could add a short script in the package.json to build the types.

@weaverryan weaverryan added the Feature New Feature label May 24, 2022
@weaverryan weaverryan merged commit 02420f0 into symfony:main May 24, 2022
@weaverryan weaverryan deleted the types-in-package branch May 24, 2022 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript typings are not found
4 participants