diff --git a/core/suggestion.js b/core/suggestion.js index 086a9b9..2300a07 100644 --- a/core/suggestion.js +++ b/core/suggestion.js @@ -520,6 +520,10 @@ module.exports = { selector: 'CallExpression[callee.property.name="toString"][callee.optional=false][arguments.length=0][optional=false]', message: 'Use String() instead.' + }, + { + selector: '[returnType.type="TSTypeAnnotation"]>TSTypeAnnotation>TSVoidKeyword', + message: 'Use undefined for non-returning functions of unknown for callbacks' } ], diff --git a/examples/typescript-lib/src/add.ts b/examples/typescript-lib/src/add.ts index 2444b97..7ebc03f 100644 --- a/examples/typescript-lib/src/add.ts +++ b/examples/typescript-lib/src/add.ts @@ -18,7 +18,7 @@ export function addSync(x: number, y: number): number { * @param y The value to add to x. * @param cb The callback that will be called with the sum of x and y. */ -export function addAsync(x: number, y: number, cb: Callback): void { +export function addAsync(x: number, y: number, cb: Callback): undefined { cb(null, x + y) } diff --git a/examples/typescript-lib/src/substract.ts b/examples/typescript-lib/src/substract.ts index 343334f..8b658b1 100644 --- a/examples/typescript-lib/src/substract.ts +++ b/examples/typescript-lib/src/substract.ts @@ -19,7 +19,7 @@ export function substractSync(x: number, y: number): number { * @param y The value to substract from x. * @param cb The callback that will be called with the difference between x and y. */ -export function substractAsync(x: number, y: number, cb: Callback): void { +export function substractAsync(x: number, y: number, cb: Callback): undefined { addAsync(x, -y, (error, result) => { if (error) { cb(error) diff --git a/examples/typescript-lib/src/types.ts b/examples/typescript-lib/src/types.ts index 44321e2..40e4b41 100644 --- a/examples/typescript-lib/src/types.ts +++ b/examples/typescript-lib/src/types.ts @@ -1 +1 @@ -export type Callback = (error: Error | null, sum?: T) => void +export type Callback = (error: Error | null, sum?: T) => unknown diff --git a/examples/typescript-preact/src/components/ErrorHandler/index.tsx b/examples/typescript-preact/src/components/ErrorHandler/index.tsx index 41a62e8..3781093 100644 --- a/examples/typescript-preact/src/components/ErrorHandler/index.tsx +++ b/examples/typescript-preact/src/components/ErrorHandler/index.tsx @@ -29,7 +29,7 @@ export class ErrorHandler extends Component { * * @param error The error that was thrown */ - componentDidCatch(error: Error): void { + componentDidCatch(error: Error): undefined { this.setState({ error }) } diff --git a/examples/typescript-preact/src/components/ItemForm/index.tsx b/examples/typescript-preact/src/components/ItemForm/index.tsx index 5ef88c4..8feda78 100644 --- a/examples/typescript-preact/src/components/ItemForm/index.tsx +++ b/examples/typescript-preact/src/components/ItemForm/index.tsx @@ -10,7 +10,7 @@ interface ItemFormProps { /** * Called when the form is submitted */ - onSubmit: (item: Item) => void + onSubmit: (item: Item) => unknown } /** diff --git a/examples/typescript-react/src/components/ErrorHandler/index.tsx b/examples/typescript-react/src/components/ErrorHandler/index.tsx index d203be5..8195fa1 100644 --- a/examples/typescript-react/src/components/ErrorHandler/index.tsx +++ b/examples/typescript-react/src/components/ErrorHandler/index.tsx @@ -36,7 +36,7 @@ export class ErrorHandler extends Component { * @param error The error that was thrown * @param errorInfo The React error information */ - componentDidCatch(error: Error, errorInfo: ErrorInfo): void { + componentDidCatch(error: Error, errorInfo: ErrorInfo): undefined { this.setState({ error, errorInfo }) } diff --git a/examples/typescript-react/src/components/ItemForm/index.tsx b/examples/typescript-react/src/components/ItemForm/index.tsx index ee2b1d4..82746fd 100644 --- a/examples/typescript-react/src/components/ItemForm/index.tsx +++ b/examples/typescript-react/src/components/ItemForm/index.tsx @@ -9,7 +9,7 @@ interface ItemFormProps { /** * Called when the form is submitted */ - onSubmit: (item: Item) => void + onSubmit: (item: Item) => unknown } /**