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
fix(typescript): type declarations #647
Conversation
typescript
typescript
plugin
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 :) |
typescript
plugin
packages/typescript/types/index.d.ts
Outdated
@@ -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[]>; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@shellscape this one looks ready as well and should fix all TypeScript errors 👍 |
packages/typescript/tsconfig.json
Outdated
"include": ["src/**/*", "types/**/*"] | ||
"include": ["src/**/*", "types/**/*"], | ||
"compilerOptions": { | ||
"skipLibCheck": false |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
I don't understand how disabling a check would help prevent regressions. What I normally do is rename the |
Enabling the lib check will also typecheck the 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. |
Will it? If that's true then this PR isn't necessary because everything builds and all tests pass with |
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 |
@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>
Cool. I’ve updated the branch and removed |
ed2c87d
to
5e980f6
Compare
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 |
There was a problem hiding this 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
@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. |
I'll create an issue and attempt a PR to resolve it. |
Rollup Plugin Name:
typescript
This PR contains:
Are tests included?
Breaking Changes?
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 theskipLibCheck
option.