Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing additional props via JSX is an error in TS 2.3. #15731

Closed
danvk opened this issue May 10, 2017 · 4 comments
Closed

Passing additional props via JSX is an error in TS 2.3. #15731

danvk opened this issue May 10, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@danvk
Copy link
Contributor

danvk commented May 10, 2017

TypeScript Version: 2.3.2

Code

interface ChildProps { val: number; }
interface ParentProps { val: number; str: string; }

const ChildComponent = (props: ChildProps) => <div>{props.val}</div>;

const ParentComponent = (props: ParentProps) =>
     <ChildComponent {...props} />;
           // ERROR: ~~~~~~~~~~ Property 'str' does not exist on type 'IntrinsicAttributes & ChildProps'.

function child(props: ChildProps) {}
function parent(props: ParentProps) {
  child(props);  // OK
}

Expected behavior:

I updated my project from TypeScript 2.2 --> 2.3.2 and began getting errors along these lines.

I'd expect passing props via JSX to be similar to passing a parameter to a function: it's OK so long as the parameter is compatible with the type that the function specifies. But this doesn't seem to be the case with JSX. The attributes you pass must match the Props type precisely. No additional attributes are allowed.

But the React runtime is fine with additional attributes and this makes it difficult to use spread props.

This might be by design, see #10393. But it's strange that the analogy with passing parameters to a function breaks down, especially since this is exactly how JSX is implemented.

cc @jacobbaskin

Actual behavior:

@yuit yuit added the Duplicate An existing issue was already created label May 10, 2017
@yuit
Copy link
Contributor

yuit commented May 10, 2017

This is a duplicate for #15463 ...we have a fix in nightly and will have it for 2.3.3 as well

@yuit yuit closed this as completed May 10, 2017
@robin-anil
Copy link

@yuit Any eta for 2.3.3 ? Looks like it fixes a large swath of issues we have been facing.

@yuit
Copy link
Contributor

yuit commented May 12, 2017

@r-tock 2.3.3 should be out next week

@JoshGlazebrook
Copy link

JoshGlazebrook commented Jun 3, 2017

Was this pushed out in 2.3.3? I'm having this issue with 2.3.4.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants