Generic components fail to typecheck
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- compilers
Research direction
Start by reproducing the generic @Component with its @Prop and @Event declarations, then inspect the generated src/components.d.ts where the unresolved Data type is reported. Determine the intended generic behavior for the generated component typings; done means the component compiles and consumer event and result types remain correctly associated with the supplied data type.
Written by the indexing model from the issue text.
Description
Stencil version:
@stencil/core@2.5.1
I'm submitting a:
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/
Current behavior:
When you try to compile a component that has a generic type based on a property type it fails to compile:
[ ERROR ] TypeScript: ./src/components.d.ts:152:17
Cannot find name 'Data'.
L151: */
L152: "data": Data[];
L153: /**
Expected behavior:
The component should compile without issues
Steps to reproduce:
Related code:
If I have a component, say a table-like component that operates on generic types (e.g. emits events of said types), is it possible to make it generic?
@Component(/* ... */)
export class MyTable<Data> {
@Prop() data: Data[] = [];
get result(): Data[] {
// data will be sorted, filtered and sliced
}
// Pass the result to parent.
@Event() update: EventEmitter<Data[]>
}
Now when a consumer sets the data property of <my-table> to say Pokemon you would expect e.g. the update event to reflect that.
type Pokemon = {
name: string;
type: string;
cp: number;
};
const pokemon: Pokemon = [
{ name: 'Pikachu', type: 'Electric', cp: 500 },
{ name: Magikarp, type: 'Water', cp: 23 },
];
myTable.data = pokemon;
myTable.addEventListener('update', (event) => {
// `event.detail` and `event.target.result` should be of type `Pokemon[]`
});
Other information:
This is only a minor annoyance as it is trivial to use unknown in this case. But it could offer a nice quality of life if fixed.
- Dominant language
- TypeScript
- Stars
- 13.1k
- Forks
- 855
- Avg merge
- 4h 7m
- Merged PRs (30d)
- 44
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stenciljs/core
-
Stencil v5
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Stencil v5
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Bug: Validated Stencil v5
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Feature: Want this? Upvote it!
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Feature: Want this? Upvote it!
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·