Skip to content
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

fix(typescript): type declarations #647

Merged
merged 1 commit into from Jan 29, 2021

Conversation

geigerzaehler
Copy link
Contributor

@geigerzaehler geigerzaehler commented Nov 13, 2020

Rollup Plugin Name: typescript

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Description

Before, using type definitions from this package without the skipLibCheck option for TypeScript would result in type checking errors. We fix this and to ensure that the types stay correct we have the checked as part of the build process by disabling the skipLibCheck option.

@geigerzaehler geigerzaehler changed the title ## Rollup Plugin Name: typescript Fix type declarations in typescript plugin Nov 13, 2020
@shellscape
Copy link
Collaborator

Thanks for opening this PR 🎉

We've got one similar in #633 so I'd like to give the author of that one time to weigh in. Hang in there, we'll get this resolved soon :)

@shellscape shellscape changed the title Fix type declarations in typescript plugin fix(typescript): type declarations Nov 28, 2020
@@ -41,7 +41,7 @@ export interface RollupTypescriptPluginOptions {
type ElementType<T extends Array<any>> = T extends (infer U)[] ? U : never;

export type TransformerStage = keyof CustomTransformers;
type StagedTransformerFactory<T extends TransformerStage> = ElementType<CustomTransformers[T]>;
type StagedTransformerFactory<T extends TransformerStage> = ElementType<CustomTransformers[]>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be an error. This change means that it isn't the list of a single transform step anymore, but an array of an array of transforms.

The type of CustomTransformers is:

export interface CustomTransformers {
    /** Custom transformers to evaluate before built-in .js transformations. */
    before?: (TransformerFactory<SourceFile> | CustomTransformerFactory)[];
    /** Custom transformers to evaluate after built-in .js transformations. */
    after?: (TransformerFactory<SourceFile> | CustomTransformerFactory)[];
    /** Custom transformers to evaluate after built-in .d.ts transformations. */
    afterDeclarations?: (TransformerFactory<Bundle | SourceFile> | CustomTransformerFactory)[];
}

So CustomTransformers[T] already is an array. Making another array from it, removes the error but is probably semantically incorrect.

See #633 (comment) for a discussion of alternative solutions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn’t quite sure what was happening here so I just tried to make it work. I’ve used the first solution you suggested to fix the issue.

@apfelbox
Copy link
Contributor

apfelbox commented Dec 1, 2020

@shellscape this one looks ready as well and should fix all TypeScript errors 👍

"include": ["src/**/*", "types/**/*"]
"include": ["src/**/*", "types/**/*"],
"compilerOptions": {
"skipLibCheck": false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the default, so you shouldn't really need to change it here

https://www.typescriptlang.org/docs/handbook/compiler-options.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re correct, it is the default for the compiler. But the project tsconfig sets it to true. I tried to be unintrusive and not change it for the whole project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed that. Though it looks like we can remove it in the base config without any additional changes, so that might be the better way to go: #700

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If needed, could we roll back this change in order to merge the change for the type that is breaking in #626 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the thing to do would be to merge #700 instead of changing this file, but perhaps @shellscape could weigh in on whether we can merge that one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#700 is merged, please @geigerzaehler can you revert this change and rebase your PR?

@benmccann
Copy link
Contributor

We fix this and to ensure that the types stay correct we have the checked as part of the build process by disabling the skipLibCheck option

I don't understand how disabling a check would help prevent regressions. What I normally do is rename the .d.ts file to .ts and put it in the source directory and then let @rollup/plugin-typescript generate the .d.ts files

@geigerzaehler
Copy link
Contributor Author

I don't understand how disabling a check would help prevent regressions. What I normally do is rename the .d.ts file to .ts and put it in the source directory and then let @rollup/plugin-typescript generate the .d.ts files

Enabling the lib check will also typecheck the .d.ts that is committed to source and force it to be correct.

I agree with you that normally you would want to avoid hand-written declaration files and instead have the compiler generate them for you. But I don’t know why this decision was made for the repo in the first place and I tried to keep the changes to a minimum.

@benmccann
Copy link
Contributor

Enabling the lib check will also typecheck the .d.ts that is committed to source and force it to be correct.

Will it? If that's true then this PR isn't necessary because everything builds and all tests pass with skipLibCheck removed in #700

@geigerzaehler
Copy link
Contributor Author

Will it? If that's true then this PR isn't necessary because everything builds and all tests pass with skipLibCheck removed in #700

Great find. I don’t understand the build and check system for this project and I assumed that it would do something that is equivalent to tsc -p packages/typescript. Running this command fails for me without the fix but I does not seem to be run on CI so I guess that is something that should be enabled.

@shellscape
Copy link
Collaborator

@geigerzaehler we merged #700, could you take another look at this?

We fix the type declaration file for the `typescript` plugin.

Signed-off-by: Thomas Scholtes <thomas-scholtes@gmx.de>
@geigerzaehler
Copy link
Contributor Author

@geigerzaehler we merged #700, could you take another look at this?

Cool. I’ve updated the branch and removed skipLibCheck: false. So this PR now fixes the issue but the CI still doesn’t not do type checking so this might break again. Since I’m not familiar with the CI setup it would make sense to tackle this separately.

@fernandopasik
Copy link
Contributor

Looking at https://github.com/rollup/plugins/blob/master/.circleci/config.yml I don't see any task to do typescript type checks

Each project in the monorepo has the task test:ts which does run tsc and check the types

Copy link
Contributor

@fernandopasik fernandopasik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case that could be an improvement for the CI.
This PR scope is to fix a type issue

@shellscape
Copy link
Collaborator

@fernandopasik that's correct, plugins should run type checking independently. since the typescript plugin doesn't have that, I'll make a note to add it following merging of this PR. thanks for pointing that out.

@shellscape shellscape merged commit 181b929 into rollup:master Jan 29, 2021
@fernandopasik
Copy link
Contributor

I'll create an issue and attempt a PR to resolve it.

@fernandopasik
Copy link
Contributor

#779

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants