TypeScript is throwing a fit because it thinks you’re trying to pass an argument to a function or constructor, but you haven’t actually provided anything for it to use.
This usually means there’s a missing piece of information somewhere in your code where TypeScript expects it.
Common Causes and Fixes
1. Missing Argument in Function Call
- Diagnosis: Review the function call that’s causing the error. TypeScript is telling you a specific parameter is missing.
- Cause: You’ve called a function but omitted one of its required arguments.
- Fix: Add the missing argument with a valid value. For example, if
myFunction(a)is causing the error andmyFunctionexpects(a: number, b: string), you needmyFunction(a, "some string"). - Why it works: You’re satisfying the function’s signature by providing all its declared parameters.
2. Missing Argument in Constructor Call
- Diagnosis: Look at the
new ClassName(...)expression. - Cause: Similar to function calls, you’ve instantiated a class without providing all the arguments required by its constructor.
- Fix: Ensure all parameters defined in the class’s constructor are supplied. If
new MyClass()errors andMyClasshasconstructor(config: ConfigObject), change it tonew MyClass({ property1: value }). - Why it works: The constructor needs specific inputs to properly initialize the object.
3. Incorrect Type Assertion Syntax
- Diagnosis: Search for angle-bracket type assertions like
<Type>variable. - Cause: You’re using the JSX-style angle-bracket type assertion (
<Type>value) in a context where it’s ambiguous with JSX tags, and TypeScript is interpreting it as a function call with a missing argument. - Fix: Use the
askeyword for type assertions instead. Change<string>someValuetosomeValue as string. - Why it works: The
askeyword is unambiguous and clearly signals a type assertion, avoiding confusion with function calls.
4. Generic Type Argument Mismatch
- Diagnosis: Examine calls to generic functions or the instantiation of generic classes.
- Cause: You’re providing type arguments to a generic function or class, but the syntax is incorrect, leading TypeScript to believe an argument expression is missing. This can happen if you’re trying to pass a type argument (
<T>) where a value argument is expected. - Fix: Ensure you’re using the correct syntax for passing type arguments (e.g.,
<MyType>) versus value arguments (e.g.,myValue). If you’re calling a generic function likeprocess<MyData>(someValue), the error might stem from incorrectly trying to pass a type argument where a value should be. The fix would be to ensuresomeValueis indeed the correct type and the generic typeMyDatais correctly specified if needed. For example, a generic functionfunction identity<T>(arg: T): Tcalled asidentity<string>("hello")is correct. If you mistyped it asidentity("hello", <string>)or similar, you’d get an error. - Why it works: Correctly distinguishing between type parameters and value parameters allows TypeScript to properly infer or validate types.
5. Missing await for a Promise (and expecting a value)
- Diagnosis: Look for places where you’re using a Promise object directly where a resolved value is expected.
- Cause: You’re trying to use the result of an asynchronous operation (a Promise) as if it were already its resolved value, but you’ve forgotten to
awaitit. TypeScript sees the Promise object itself and, in some contexts, might interpret this as an attempt to pass the Promise object as an argument where a specific type is expected, leading to the "argument expression expected" error if the function signature implies a non-Promise type. - Fix: Use
awaitbefore the Promise-returning function call within anasyncfunction. For example, changeconst result = fetchData();toconst result = await fetchData();. - Why it works:
awaitpauses execution until the Promise resolves, then unwraps its value, providing the actual data that the function expects.
6. Incorrectly Structured Template Literal Types
- Diagnosis: Examine complex template literal type definitions or their usage.
- Cause: In advanced TypeScript, you might be defining or using template literal types in a way that TypeScript misinterprets the structure, expecting an expression where a type definition is being formed. This is less common but can occur with intricate type manipulations.
- Fix: Carefully review the syntax of your template literal types. Ensure that any interpolated types or expressions are correctly enclosed and that the overall structure adheres to TypeScript’s type definition syntax. For instance,
type Greeting =Hello, ${string}!`` is valid. An error might occur if you try to use something liketype BadGreeting =Hello, ${string!}(missing closing brace), which TypeScript might parse in a way that leads to the argument error. - Why it works: Correct template literal syntax ensures TypeScript can properly parse and construct the intended type.
The next error you’ll likely encounter after fixing TS1135 is a type mismatch, as the underlying issue was likely a structural problem that TS1135 flagged before it could do a deeper type check.