Property or signature expected error in TypeScript

avatar
Borislav Hadzhiev

Last updated: Feb 28, 2024
2 min

banner

# Property or signature expected error in TypeScript

The "Property or signature expected" error occurs when we have a syntax error when declaring a type or interface.

To solve the error, make sure to separate the properties and types by a colon and wrap properties that contain hyphens or spaces in quotes.

Here are 3 examples of how the error occurs.

index.ts
interface Employee { // ⛔️ Error: Property or signature expected.ts(1131) first-name: string; } // -------------------------------------------------------- type Example = { // ⛔️ Error: two words: string; } // -------------------------------------------------------- type Person = { // ⛔️ Error: country = string; }

property signature expected error

The cause of the error in the first example is that the property name in the interface contains a hyphen.

# Wrap hyphenated properties in quotes

If a property name in an interface, type or object contains a hyphen, we have to wrap it in quotes.

index.ts
interface Employee { 'first-name': string; } const emp: Employee = { 'first-name': 'Bobby', };

wrap hyphenated properties in quotes

The code for this article is available on GitHub

Note that we had to wrap the property in quotes both in the interface and when declaring an object of type Employee.

The same is the case with spaces (and most other separators).

# Wrap properties that contain spaces in quotes

If an object, type or interface property contains a space, wrap it in quotes.

index.ts
type Example = { 'two words': string; }; const e: Example = { 'two words': 'hello world', };

wrap properties that contain spaces in quotes

# Separate properties and types by a colon

Another common cause of the error is mistakenly separating the property and the type by an equal sign or any other symbol that isn't a colon.

index.ts
type Person = { // ⛔️ Error: Property or signature expected.ts(1131) country = string; }

Always make sure to separate the property name and the type by a colon.

index.ts
type Person = { country: string; }; const person: Person = { country: 'Germany', };
The code for this article is available on GitHub

Note that you can't provide default values in types and interfaces, because TypeScript only helps us catch bugs during development.

All of the types and interfaces you have defined will be removed when your code is compiled to JavaScript.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.