Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .changeset/constructed-carriers-corrolate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
"@biomejs/biome": patch
---

Fixed [#8292](https://github.com/biomejs/biome/issues/8292): Implement tracking
of types of TypeScript constructor parameter properties.

This resolves certain false negatives in `noFloatingPromises` and other typed
rules.

#### Example

```ts
class AsyncClass {
async returnsPromise() {
return 'value';
}
}

class ShouldBeReported {
constructor(public field: AsyncClass) { }
// ^^^^^^^^^^^^----------------- Parameter property declaration

async shouldBeReported() {
// `noFloatingPromises` will now report the following usage:
this.field.returnsPromise();
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* should generate diagnostics */

class AsyncClass {
async returnsPromise() {
return 'value';
}
}

class ShouldBeReported {
constructor(public field: AsyncClass) { }

async shouldBeReported() {
this.field.returnsPromise();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: issue8292.ts
---
# Input
```ts
/* should generate diagnostics */

class AsyncClass {
async returnsPromise() {
return 'value';
}
}

class ShouldBeReported {
constructor(public field: AsyncClass) { }

async shouldBeReported() {
this.field.returnsPromise();
}
}

```

# Diagnostics
```
issue8292.ts:13:9 lint/nursery/noFloatingPromises FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

i A "floating" Promise was found, meaning it is not properly handled and could lead to ignored errors or unexpected behavior.

12 │ async shouldBeReported() {
> 13 │ this.field.returnsPromise();
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14 │ }
15 │ }

i This happens when a Promise is not awaited, lacks a `.catch` or `.then` rejection handler, or is not explicitly ignored using the `void` operator.

i Unsafe fix: Add await operator.

13 │ ········await·this.field.returnsPromise();
│ ++++++

```
Loading