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 new rule#8443
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
Closed
StyleShit wants to merge81 commits intotypescript-eslint:mainfromStyleShit:feat/require-types-exports
Uh oh!
There was an error while loading.Please reload this page.
Closed
Changes fromall commits
Commits
Show all changes
81 commits Select commitHold shift + click to select a range
9a0c28a
feat(eslint-plugin): [require-types-exports] add new rule
StyleShit7778868
wip
StyleShit12fce5b
wip
StyleShitd62f86c
lint
StyleShit0ebebd2
wip
StyleShit30e9aa9
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShitbfee791
spelling...
StyleShitb309b51
wip
StyleShit6aa6446
wip
StyleShit892c368
wip
StyleShit0e8e58f
tuple generic
StyleShitf4018a8
wip
StyleShit89a8344
wip
StyleShitb2138e3
wip
StyleShitfeedefd
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShit1161db0
wip
StyleShitd9875b3
refactor
StyleShit6338202
make it shorter & more readable
StyleShit428b2c1
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShit2cb3455
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShit1812e37
fix nested types in functions
StyleShit4bee779
fix docs
StyleShit26e7be7
add inferred return type test case
StyleShite57985a
stupidly check for variable types
StyleShitcbb784c
support default exported variable
StyleShit2f2dfa4
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShit37a0171
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShit6fb274a
update docs
StyleShit4672fe1
wip
StyleShitc79b5cb
wip
StyleShit279055a
wip
StyleShit7897abf
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShit7082960
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShit2f81933
improve types
StyleShit0f788d2
improve type reference search
StyleShit6cec0f5
don't report types from default library
StyleShit497957a
getTypeName
StyleShit702d4d0
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShit700ff85
move utils out of the closure
StyleShit9a155b3
support namespaced types
StyleShit8d0d000
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShitb65f9c4
fix namespaced imports
StyleShit078e24a
WIP
StyleShited23162
wip
StyleShitac224eb
fix propertykey tests
StyleShit417cc91
ReturnType test
StyleShit62f1466
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShitae1b87c
wip
StyleShitd227408
collect type references recursively
StyleShitdca52d0
lib types
StyleShited30856
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShit15fc51c
style
StyleShit59eda58
wip
StyleShitfc0858a
wip
StyleShit9d24c64
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShit94a98eb
configs
StyleShitdee0fe4
don't report generic params in call expression
StyleShit0804b24
improve function types collection
StyleShita0a4944
wip
StyleShit66a0aff
wip
StyleShitb67e1f9
remove `getVariable`
StyleShit9891e78
infer return type from return statements
StyleShitcb90d43
wip
StyleShit479f593
wip
StyleShit08f2ce2
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShite86427f
wip
StyleShita61d49f
wip
StyleShit121f475
wip
StyleShitf3f8518
wip
StyleShitab837b4
custom traversal
StyleShit1641272
some tests
StyleShitfd56a1c
add missing tests
StyleShitb0613d5
report default exported call expression
StyleShitb9f1148
report types used within exported types
StyleShit0415b60
fix false positives due to ordering
StyleShita0c236e
change message
StyleShit3d5d695
wip
StyleShit2e76ce6
fix some reports
StyleShit88713cb
support keyof & typeof
StyleShitff2c0a8
simplify tsconfig
StyleShit2fd30aa
Merge remote-tracking branch 'typescript-eslint/main' into feat/requi…
StyleShitFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletionspackages/eslint-plugin/docs/rules/require-types-exports.mdx
This file contains hidden or 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,80 @@ | ||
--- | ||
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 module, it is recommended to export also all the | ||
types that are used in their declarations. This is useful for consumers of the | ||
module, as it allows them to use the types in their own code without having 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 your code. | ||
## Examples | ||
<Tabs> | ||
<TabItem value="❌ Incorrect"> | ||
```ts | ||
type Arg = string; | ||
type Result = number; | ||
export function strLength(arg: Arg): Result { | ||
return arg.length; | ||
} | ||
interface Fruit { | ||
name: string; | ||
color: string; | ||
} | ||
export const getFruitName = (fruit: Fruit) => fruit.name; | ||
enum Color { | ||
Red = 'red', | ||
Green = 'green', | ||
Blue = 'blue', | ||
} | ||
export declare function getRandomColor(): Color; | ||
``` | ||
</TabItem> | ||
<TabItem value="✅ Correct"> | ||
```ts | ||
export type Arg = string; | ||
export type Result = number; | ||
export function strLength(arg: Arg): Result { | ||
return arg.length; | ||
} | ||
export interface Fruit { | ||
name: string; | ||
color: string; | ||
} | ||
export const getFruitName = (fruit: Fruit) => fruit.name; | ||
export enum Color { | ||
Red = 'red', | ||
Green = 'green', | ||
Blue = 'blue', | ||
} | ||
export declare function getRandomColor(): Color; | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
## When Not To Use It | ||
When you don't want to enforce exporting types that are used in exported functions declarations. |
1 change: 1 addition & 0 deletionspackages/eslint-plugin/src/configs/all.ts
This file contains hidden or 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
1 change: 1 addition & 0 deletionspackages/eslint-plugin/src/configs/strict-type-checked.ts
This file contains hidden or 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
1 change: 1 addition & 0 deletionspackages/eslint-plugin/src/configs/strict.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/array-type.ts
This file contains hidden or 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
6 changes: 3 additions & 3 deletionspackages/eslint-plugin/src/rules/ban-ts-comment.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/class-literal-property-style.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/class-methods-use-this.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/comma-spacing.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/consistent-generic-constructors.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/consistent-indexed-object-style.ts
This file contains hidden or 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
6 changes: 3 additions & 3 deletionspackages/eslint-plugin/src/rules/consistent-return.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/consistent-type-exports.ts
This file contains hidden or 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
8 changes: 4 additions & 4 deletionspackages/eslint-plugin/src/rules/consistent-type-imports.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/explicit-function-return-type.ts
This file contains hidden or 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
8 changes: 4 additions & 4 deletionspackages/eslint-plugin/src/rules/explicit-member-accessibility.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/explicit-module-boundary-types.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/indent.ts
This file contains hidden or 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
2 changes: 2 additions & 0 deletionspackages/eslint-plugin/src/rules/index.ts
This file contains hidden or 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
4 changes: 2 additions & 2 deletionspackages/eslint-plugin/src/rules/lines-between-class-members.ts
This file contains hidden or 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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.