Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Add lint rule to prefer map((): T => {}) over map<T>(() => {}) #6995

Merged
merged 2 commits into from
Oct 23, 2023

Conversation

jtbandes
Copy link
Member

@jtbandes jtbandes commented Oct 14, 2023

User-Facing Changes
None

Description

TypeScript currently widens inferred types of function expressions (microsoft/TypeScript#241). This results in the following sad situation:

const a = [1, 2, 3];

type T = {
    x: number;
}

a.map((i): T => {
    return {
        x: i,
        y: "oopsie",  // error 👍
    }
});

a.map<T>((i) => {
    return {
        x: i,
        y: "oopsie",  // no error 🤔
    }
});

This PR adds a lint rule to automatically replace map<T>((i) => ... with map((i): T => ....

Depends on #6989 to merge first.

Resolves FG-5336

Copy link
Contributor

@defunctzombie defunctzombie left a comment

Choose a reason for hiding this comment

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

magical - life is so hard in the salt mines

@jtbandes jtbandes merged commit 170ef5a into main Oct 23, 2023
13 of 14 checks passed
@jtbandes jtbandes deleted the jacob/no-map-type-argument branch October 23, 2023 16:40
pezy pushed a commit to pezy/studio that referenced this pull request Oct 25, 2023
…oxglove#6995)

**User-Facing Changes**
None

**Description**

TypeScript currently widens inferred types of function expressions
(microsoft/TypeScript#241). This results in
the following [sad
situation](https://www.typescriptlang.org/play?#code/MYewdgzgLgBAhjAvDA2gRgDQwExYMwC6A3AFAlQCeADgKYwAqSMA3iTOzAB4BcMYArgFsARjQBOpAL5k4AOkFwqACiUBLAJS9GiAHwsSAegMwAegH42HMTSj8xYfRyddeqjJecwKvAEQgQVBCqND5YMEYw4mIgYjCAvBuAsjseMNKS6qQkcgpUADz0OioaSHqsEebJ1rb2jp4uMG7JTt4wfgFBIWERYCCRYtGxgHwbgCi7yanpZEA):

```ts
const a = [1, 2, 3];

type T = {
    x: number;
}

a.map((i): T => {
    return {
        x: i,
        y: "oopsie",  // error 👍
    }
});

a.map<T>((i) => {
    return {
        x: i,
        y: "oopsie",  // no error 🤔
    }
});
```

This PR adds a lint rule to automatically replace `map<T>((i) => ...`
with `map((i): T => ...`.

Depends on foxglove#6989 to merge first.

Resolves FG-5336
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants