Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [require-types-exports] add rule#10554
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
9a0c28a
7778868
12fce5b
d62f86c
0ebebd2
30e9aa9
bfee791
b309b51
6aa6446
892c368
0e8e58f
f4018a8
89a8344
b2138e3
feedefd
1161db0
d9875b3
6338202
428b2c1
2cb3455
1812e37
4bee779
26e7be7
e57985a
cbb784c
2f2dfa4
37a0171
6fb274a
4672fe1
c79b5cb
279055a
7897abf
7082960
2f81933
0f788d2
6cec0f5
497957a
702d4d0
700ff85
9a155b3
8d0d000
b65f9c4
078e24a
ed23162
ac224eb
417cc91
62f1466
ae1b87c
d227408
dca52d0
ed30856
15fc51c
59eda58
fc0858a
9d24c64
94a98eb
dee0fe4
0804b24
a0a4944
66a0aff
b67e1f9
9891e78
cb90d43
479f593
08f2ce2
e86427f
a61d49f
121f475
f3f8518
ab837b4
1641272
fd56a1c
b0613d5
b9f1148
0415b60
a0c236e
3d5d695
2e76ce6
88713cb
ff2c0a8
2fd30aa
d977245
a03713a
2f44044
57181fd
8563e09
e056cac
196d148
c42d42f
e11e05a
cc90f7d
5458408
0061e98
b629590
6de73eb
4188eb0
55cca12
fb0c4f3
dd7c454
6d04460
e9ada94
e09b7d9
8dc9607
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
exporttype ExportAndImportKind = 'type' | 'value'; | ||
export type ExportKind = ExportAndImportKind; | ||
export type ImportKind = ExportAndImportKind; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
description: 'Require exporting types that are used in exported entities.' | ||
--- | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
> 🛑 This file is source code, not the primary documentation location! 🛑 | ||
> | ||
> See **https://typescript-eslint.io/rules/require-types-exports** for documentation. | ||
When exporting entities from a file, it is often useful to export also all the types that are used in their declarations. | ||
Doing so ensures consumers of the file can directly import and use those types when using those entities. | ||
Otherwise, consumers may have to use utility types like [`Parameters`](https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype) or [`ReturnType`](https://www.typescriptlang.org/docs/handbook/utility-types.html#returntypetype) in order to extract the types from the entities. | ||
## Examples | ||
<Tabs> | ||
<TabItem value="❌ Incorrect"> | ||
```ts | ||
interface Fruit { | ||
name: string; | ||
color: string; | ||
} | ||
export const getFruitName = (fruit: Fruit) => fruit.name; | ||
``` | ||
```ts | ||
const fruits = { | ||
apple: '🍏', | ||
banana: '🍌', | ||
}; | ||
export const getFruit = (key: keyof typeof fruits) => fruits[key]; | ||
``` | ||
```ts | ||
enum Color { | ||
Red = 'red', | ||
Green = 'green', | ||
Blue = 'blue', | ||
} | ||
export declare function getRandomColor(): Color; | ||
``` | ||
</TabItem> | ||
<TabItem value="✅ Correct"> | ||
```ts | ||
export interface Fruit { | ||
name: string; | ||
color: string; | ||
} | ||
export const getFruitName = (fruit: Fruit) => fruit.name; | ||
``` | ||
```ts | ||
export const fruits = { | ||
apple: '🍏', | ||
banana: '🍌', | ||
}; | ||
export const getFruit = (key: keyof typeof fruits) => fruits[key]; | ||
``` | ||
```ts | ||
export enum Color { | ||
Red = 'red', | ||
Green = 'green', | ||
Blue = 'blue', | ||
} | ||
export declare function getRandomColor(): Color; | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
## When Not To Use It | ||
If your files utilize many complex self-referential types that you don't want external consumers to reference, you may want to avoid this rule for those cases. | ||
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -14,12 +14,12 @@ import { | ||
} from '../util/getMemberHeadLoc'; | ||
import { rangeToLoc } from '../util/rangeToLoc'; | ||
exporttype AccessibilityLevel = | ||
| 'explicit' // require an accessor (including public) | ||
| 'no-public' // don't require public | ||
| 'off'; // don't check | ||
exportinterface Config { | ||
accessibility?: AccessibilityLevel; | ||
ignoredMethodNames?: string[]; | ||
overrides?: { | ||
@@ -31,9 +31,9 @@ interface Config { | ||
}; | ||
} | ||
exporttype Options = [Config]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Side note: Next rule has I lined the options and does not have Config as separate type. Maybe for consistency this type could be inlined too, if you are doing another PR just for these export changes :) Or if the separate Config type is preferred, maybe there could be some follow up | ||
exporttype MessageIds = | ||
| 'addExplicitAccessibility' | ||
| 'missingAccessibility' | ||
| 'unwantedPublicAccessibility'; | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.