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
9a0c28a777886812fce5bd62f86c0ebebd230e9aa9bfee791b309b516aa6446892c3680e8e58ff4018a889a8344b2138e3feedefd1161db0d9875b36338202428b2c12cb34551812e374bee77926e7be7e57985acbb784c2f2dfa437a01716fb274a4672fe1c79b5cb279055a7897abf70829602f819330f788d26cec0f5497957a702d4d0700ff859a155b38d0d000b65f9c4078e24aed23162ac224eb417cc9162f1466ae1b87cd227408dca52d0ed3085615fc51c59eda58fc0858a9d24c6494a98ebdee0fe40804b24a0a494466a0affb67e1f99891e78cb90d43479f59308f2ce2e86427fa61d49f121f475f3f8518ab837b41641272fd56a1cb0613d5b9f11480415b60a0c236e3d5d6952e76ce688713cbff2c0a82fd30aad977245a03713a2f4404457181fd8563e09e056cac196d148c42d42fe11e05acc90f7d54584080061e98b6295906de73eb4188eb055cca12fb0c4f3dd7c4546d04460e9ada94e09b7d98dc9607File 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]; | ||
Contributor 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.