question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS2739: Type is missing the following properties from type

See original GitHub issue

TypeScript Version: 3.3.0-dev.201xxxxx

Search Terms:

Code

export const sp = '_@_';

export interface IWordsOutput
{
	_source?: any,

	s?: RegExp,
	r?: string | IRegExpCallback,

	flags?: string,
}

export interface IRegExpCallback
{
	($0: string, $1?: string, $2?: string, $3?: string, ...argv): string;
}

export interface IWords extends IWordsOutput
{
	[0]: string | RegExp,
	[1]: string | IRegExpCallback,
	[2]?: string,
}

export const words_source: IWords[] = [

	// this is work
	['HP', 'HP'],

	// Error:TS2739: Type 'string[]' is missing the following properties from type 'IWords': [0], [1]
	(function ()
	{
		let jobclass = '(?:A|B|C)';

		return [`${jobclass}${sp}${jobclass}`, '$1・$2'];
	})(),

];

Expected behavior:

no error

Actual behavior:

Error:TS2739: Type ‘string[]’ is missing the following properties from type ‘IWords’: [0], [1]

Playground Link:

Related Issues:

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:7
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

25reactions
prakarangscommented, May 21, 2019

Hi, I have the same error but slightly different scenario. I have a functional component wrapped with a redux connect function. Some props are provided via mapStateToProps. However, When calling a component without adding all the props gives me TS2739 error.

Sample code

button.tsx

export interface Props {
  canPost: boolean;
  postMethod: (name: string) => void;
  name: string;
}

const postButton = ({ canPost, postMethod, name }) => {
  const postSomething = () => {
    canPost && postMethod(name);
  };
  return <button  onClick={postSomething}>Do somthing</button>;
}

export default postButton;

canPost and postMethod are provided via connect function as follow:

index.ts

import { connect } from 'react-redux';
import postButton from  './button';
import { postMethod } from './store/actions';

export const mapStateToProps = (state) => {
  const { canPost } = state;
  return { canPost };
};
export const mapDispatchToProps = { postMethod };

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(postButton);

Then when i call the button component somewhere else, i only want to pass in the name as prop. Not anything else, however, i received TS2739: Type is missing the following properties from type for canPost and postMethod.

otherComponent.tsx

...in return function
 <postButton name="orders" />

For now i have to type canPost and postMethod as undefined. that will fixed the issue. But it is not actually undefined. Anyone could suggest me how to handle this properly? What’s the best approach?

Many thanks in advance 😃

3reactions
iamtomhankscommented, Apr 24, 2020

Hi, I have the same error but slightly different scenario. I have a functional component wrapped with a redux connect function. Some props are provided via mapStateToProps. However, When calling a component without adding all the props gives me TS2739 error.

Sample code

button.tsx

export interface Props {
  canPost: boolean;
  postMethod: (name: string) => void;
  name: string;
}

const postButton = ({ canPost, postMethod, name }) => {
  const postSomething = () => {
    canPost && postMethod(name);
  };
  return <button  onClick={postSomething}>Do somthing</button>;
}

export default postButton;

canPost and postMethod are provided via connect function as follow:

index.ts

import { connect } from 'react-redux';
import postButton from  './button';
import { postMethod } from './store/actions';

export const mapStateToProps = (state) => {
  const { canPost } = state;
  return { canPost };
};
export const mapDispatchToProps = { postMethod };

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(postButton);

Then when i call the button component somewhere else, i only want to pass in the name as prop. Not anything else, however, i received TS2739: Type is missing the following properties from type for canPost and postMethod.

otherComponent.tsx

...in return function
 <postButton name="orders" />

For now i have to type canPost and postMethod as undefined. that will fixed the issue. But it is not actually undefined. Anyone could suggest me how to handle this properly? What’s the best approach? Did you end up fixing this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type 'X' is missing the following properties from type 'Y'
The error "Type is missing the following properties from type" occurs when the type we assign to a variable is missing some of...
Read more >
React with Typescript - Type { } is missing the following ...
As you are passing card to ProfileCard component, its passing 4 values in props. {login: string, name: string, key: number, id: number}.
Read more >
Solved - Type x is missing the following properties from type y ...
This error occurs when you are not passing all the required props or only passing some of the required props to the component....
Read more >
ts2740: type 'collection ' is missing the following properties ...
ts2740: type 'collection ' is missing the following properties from type 'record ': set, merge, mergedeep, mergewith, and 14 more. Favicon for stackoverflow.com ......
Read more >
Type 'typeof IdleState' is missing the following properties.
Type 'typeof IdleState' is missing the following properties. abstract class State { constructor() { } abstract Name(): void; abstract Enter ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found