Typescript | Warning about Missing Return Type of function, ESLint
I'd recommend using the types provided by react; they'll include the return type. If you're on the version 16.8.0 or later of react, do this:
const Component: React.FunctionComponent<Props> = (props) => (
Or use the shorthand:
const Component: React.FC<Props> = (props) => (
Prior to 16.8, you'd instead do:
const Component: React.SFC<Props> = (props) => (
Where SFC stands for "stateless functional component". They changed the name, since function components are no longer necessarily stateless.
typescript warning Missing return type on function
Just define a return type to your function:
const createDateTime = (d: number): string => {
const datetime = new Date(d * 1000);
return datetime.toLocaleDateString();
};
ESLint - missing return type on function react component - Typescript error explanation
The rule typescript-eslint/explicit-module-boundary-types is telling you that your function requires and explicit return type. From the source:
Explicit types for function return values and arguments makes it clear to any calling code what is the module boundary's input and output.
So you need to add the appropriate return type, which in your example is whatever the type of <Provider />
is:
Replace TypeOfProviderHere
with the correct type.
export default ({ children }: AppProviderProps): TypeOfProviderHere => (
<Provider store={store}>
**my code**
</Provider>
);
Missing return type on function in Jest / eslint
You need to explicitly specify the return type of the function. As function is async
, it returns a Promise
wrapped around the data returned by hotelService.getByIdAsync(Identifier)
const action = async (): Promise</*type of data wrapped in promise*/> => {
return await hotelService.getByIdAsync(Identifier);
};
React: Missing return type on function. eslint(@typescript-eslint/explicit-function-return-type)
As explained by Nicholas Tower in this answer Typescript | Warning about Missing Return Type of function, ESLint, depending on the react version that you are using, you can use any of the lines below:
If you're on the latest react version (16.8.0 or later), do this:const Component: React.FunctionComponent<Props> = (props: Props) => { }
Prior to 16.8, you'd instead do:const Component: React.SFC<Props> = (props: Props) => {}
Where SFC stands for "stateless functional component".
EDIT:------
Based on @SergioP's comment, a more idiomatic solution would be
const Test = ({ title }: Props): JSX.Element => <div>{title}</div>
Is there a way to ignore "Missing return type on function" for Angular lifecycle methods?
Based on @Ibsn's answer I could come up with this config:
"rules": {
"@typescript-eslint/explicit-module-boundary-types": [
"warn",
{
"allowedNames": ["ngOnInit", "ngOnDestroy", "ngAfterViewInit", "ngOnChanges"]
}
]
}
Related Topics
How Exactly Use and Update the Global Variables in React-Native
Passing Multiple Parameters from Angular to Rest Service
Ag-Grid Cellrender With Button Click
How to Pass the Checked and Unchecked Value of Checkboxes in Component.Ts File in Angular
Convert 12-Hour Hh:Mm Am/Pm to 24-Hour Hh:Mm
How to Enable Scrolling on Website That Disabled Scrolling
Is It Any Limit for Post Data Size in Ajax
How to Set a Header Field on Post a Form
Get the Contents of a Table Row With a Button Click
Angular2 Do Actions After Dom Has Finished Rendering
Ngx-Datatable Set Column Width Dynamically
How to Extract the User Name from an Email Address Using JavaScript
Customizing Item-Text in V-Select
React Native Flatlist With Clickable Items
Convert/Change JavaScript Document to Jquery