-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from pnowak/map-unknown-41
Fix for issue 41 - change Map to unknown
- Loading branch information
Showing
6 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
"@total-typescript/ts-reset": minor | ||
--- | ||
|
||
Added a rule, `/map-constructor`, to default `Map` to `Map<unknown, unknown>` when no arguments are passed to the constructor. | ||
|
||
Before, you'd get `any` for both key and value types. Now, the result of `Map.get` is `unknown` instead of `any`: | ||
|
||
```ts | ||
const userMap = new Map(); | ||
|
||
const value = userMap.get("matt"); // value: unknown | ||
``` | ||
|
||
This now is part of the recommended rules. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface MapConstructor { | ||
new (): Map<unknown, unknown>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { doNotExecute, Equal, Expect } from "./utils"; | ||
|
||
doNotExecute(() => { | ||
const map = new Map(); | ||
|
||
const result = map.get("foo"); | ||
|
||
type test = [Expect<Equal<typeof result, unknown>>]; | ||
}); | ||
|
||
doNotExecute(() => { | ||
const map = new Map(); | ||
|
||
map.set("Jessie", { phone: "213-555-1234", address: "123 N 1st Ave" }); | ||
|
||
const result = map.has("Jessie"); | ||
|
||
type test = [Expect<Equal<typeof result, boolean>>]; | ||
}); | ||
|
||
doNotExecute(() => { | ||
const map = new Map(); | ||
|
||
map.set("Jessie", { phone: "213-555-1234", address: "123 N 1st Ave" }); | ||
|
||
const result = map.get("Jessie"); | ||
|
||
type test = [Expect<Equal<typeof result, unknown>>]; | ||
}); | ||
|
||
doNotExecute(() => { | ||
const map = new Map(); | ||
|
||
map.set("Jessie", { phone: "213-555-1234", address: "123 N 1st Ave" }); | ||
|
||
const result = map.delete("Jessie"); | ||
|
||
type test = [Expect<Equal<typeof result, boolean>>]; | ||
}); | ||
|
||
doNotExecute(() => { | ||
const map = new Map(); | ||
|
||
map.set("Jessie", { phone: "213-555-1234", address: "123 N 1st Ave" }); | ||
map.set("Hilary", { phone: "617-555-4321", address: "321 S 2nd St" }); | ||
|
||
const size = map.size; | ||
|
||
type testSize = [Expect<Equal<typeof size, number>>]; | ||
}); | ||
|
||
doNotExecute(() => { | ||
const map = new Map(); | ||
|
||
map.set("Jessie", { phone: "213-555-1234", address: "123 N 1st Ave" }); | ||
map.set("Hilary", { phone: "617-555-4321", address: "321 S 2nd St" }); | ||
|
||
const cleared = map.clear(); | ||
|
||
type testClear = [Expect<Equal<typeof cleared, void>>]; | ||
}); |