Argument of type any is not assignable to parameter of type never

0 votes

This is my code:

const foo = (foo: string) => {
  const result = []
  result.push(foo)
}

I get the following TS error:

[ts] Argument of type 'string' is not assignable to parameter of type 'never'.

What exactly am I doing wrong?

May 31, 2022 in TypeSript by Logan
• 2,140 points
67,054 views

1 answer to this question.

0 votes

All you have to do is define your result as a string array, like this:

const result : string[] = [];

Without defining the array type, by default, it will be never. So when you tried to add a string to it, it was a type mismatch, and so it threw the error you saw.

answered May 31, 2022 by Nina
• 3,060 points

Related Questions In TypeSript

0 votes
1 answer

Only refers to a type, but is being used as a value here

To do type checking at runtime with ...READ MORE

answered Jun 8, 2022 in TypeSript by Nina
• 3,060 points
62,072 views
0 votes
1 answer

Typescript: TS7006: Parameter 'xxx' implicitly has an 'any' type

You are using the --noImplicitAny and TypeScript doesn't know ...READ MORE

answered Jun 10, 2022 in TypeSript by Nina
• 3,060 points
30,449 views
0 votes
0 answers

ngx-image-cropper imageloaded() not passing any image data to typescript file event method

I'm using ngx-image-cropper to load and crop images. According ...READ MORE

Jul 5, 2022 in TypeSript by Logan
• 2,140 points
2,121 views
0 votes
1 answer

Typescript Errors: How do I ignore the error "property does not exist on value of type"

to ignore it globally, in your tsconfig.json, ...READ MORE

answered Jul 26, 2023 in TypeSript by john

edited Mar 5, 2025 13,079 views
0 votes
1 answer

TypeScript - ',' expected.ts(1005)

You can't put statements in JSX curly braces, only expressions. You ...READ MORE

answered Jun 9, 2022 in TypeSript by Nina
• 3,060 points
17,110 views
0 votes
1 answer

TypeScript and React Native: Are the type definitions for RN styles wrong?

You can test some of ways for ...READ MORE

answered Jun 10, 2022 in TypeSript by Nina
• 3,060 points
5,661 views
0 votes
1 answer

error on aggregate and non aggregate values

Create a calculated field that outputs a ...READ MORE

answered Apr 17, 2018 in Tableau by ffdfd
• 5,550 points
1,928 views
0 votes
1 answer

TypeScript TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'

If you want a key/value data structure ...READ MORE

answered Jun 7, 2022 in TypeSript by Nina
• 3,060 points
21,446 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP