Skip to content

TSX's render function doesn't fail when generic component is without generic type #26898

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

Closed
sztrzask opened this issue Sep 5, 2018 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@sztrzask
Copy link

sztrzask commented Sep 5, 2018

TypeScript Version: 3.0.1

Search Terms: TSX, generics, required, jsx, typescript
I also read the jsx section in documentation.

Code

.tsx

import * as React from "react";

class Generics<T> extends React.Component {
  render() {
    return <span>Generics is rendered even though it's T is not defined</span>;
  }
}

export default () => (
  <h1>
    This should fail as Generics does not have a default type. <Generics />
  </h1>
);

Expected behavior:
The above code should fail during compilation.

Actual behavior:
The above code passes the compilation, even though the generic type is not provided and not defaulted

Playground Link:
https://codesandbox.io/s/4q15l927x

Related Issues:
#3960

@ajafff
Copy link
Contributor

ajafff commented Sep 5, 2018

Type parameters that cannot be inferred and don't have a default, fall back to {}.
There once was a PR to add an option to make this behavior an error. But that PR was rejected and it was decided this should be implemented in a linter instead.

And that's what I did. I implemented it as no-inferred-empty-object for my linter runtime Fimbullinter. Click here for detailed documentation about CLI usage, configuration and more.

Note that TSLint has a rule called no-inferred-empty-object-type. But that one doesn't actually work and doesn't check JSX.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Sep 17, 2018
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants