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

Enable @typescript-eslint/no-redundant-type-constituents rule #15794

Merged

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Jul 18, 2023

Q                       A
License MIT

This PR is based on #15793, which also fixes some errors reported by the no-redundant-type-constituents rule. Please review that PR first.

Summary of changes:

  • Introduce an API type parameter to the UnloadedDescriptor. It also makes it easier to track preset descriptor vs. plugin descriptor, which ensures that we are not passing incorrect API set to the descriptor.
  • Actually types the output source map, previously it is stubbed as any.
  • Fixes other errors

@JLHwung JLHwung added the PR: Internal 🏠 A type of pull request used for our changelog categories label Jul 18, 2023
@babel-bot
Copy link
Collaborator

babel-bot commented Jul 18, 2023

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/54905/

@@ -40,7 +41,7 @@ export default async function ({

mapSections.push({
offset: { line: offset, column: 0 },
map: result.map || {
map: (result.map as EncodedSourceMap) || {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This cast is unfortunate because the EncodedSourceMap in trace-mapping

export interface SourceMapV3 {
    file?: string | null;
    names: string[];
    sourceRoot?: string;
    sources: (string | null)[];
    sourcesContent?: (string | null)[];
    version: 3;
}
export interface EncodedSourceMap extends SourceMapV3 {
    mappings: string;
}

is slightly different to the one in gen-mapping.

export interface SourceMapV3 {
    file?: string | null;
    names: readonly string[];
    sourceRoot?: string;
    sources: readonly (string | null)[];
    sourcesContent?: readonly (string | null)[];
    version: 3;
}
export interface EncodedSourceMap extends SourceMapV3 {
    mappings: string;
}

Copy link
Member

Choose a reason for hiding this comment

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

@jridgewell Maybe you want to align them


// The absolute path of the file being compiled.
filename: string | void;
declare filename: string | void;
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't use declare here, since the constructor then sets these property (and we do not want to walk the prototype checking if they are already there)

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 mark them as declare because currently class properties are transpiled to initialization assignments in constructor as we are targeting Node.js 6: https://unpkg.com/@babel/core@7.22.9/lib/transformation/plugin-pass.js, this change will get rid of such extra assignments.

But since we will ship native class properties in Babel 8, I am happy to revert that.

if (typeof value === "function") {
const factory = maybeAsync(
value,
value as (api: API, options: {}, dirname: string) => unknown,
Copy link
Contributor Author

@JLHwung JLHwung Jul 18, 2023

Choose a reason for hiding this comment

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

I wish I could get rid of the typing cast here, the typeof check here can not rule out {} completely as it could be Function object.

Suggestions are welcome.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ehoogeveen-medweb My bad. I was meant for object as I typed value as an union of object and a specific function:

value: object | ((api: API, options: Options, dirname: string) => unknown);

but for some reason the typeof check does not rule out the object completely.

@ehoogeveen-medweb
Copy link
Contributor

ehoogeveen-medweb commented Jul 18, 2023

IIRC {} in TypeScript effectively means "anything other than undefined or null", whereas object means "any non-primitive type". Did you want the former or the latter?

Playground example

See also this comment about why {} is included in the default configuration for @typescript-eslint/ban-types.

@JLHwung JLHwung force-pushed the enable-no-redundant-type-constituents branch from 0e20ec5 to 1487600 Compare July 19, 2023 14:06
@nicolo-ribaudo nicolo-ribaudo merged commit a5b300b into babel:main Jul 22, 2023
57 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the enable-no-redundant-type-constituents branch July 22, 2023 13:17
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants