Generic and polymorphic props
Concept and boundary
A generic component can preserve the relationship between items and a renderer callback. Inference from the item array contextualizes the callback parameter. This example uses a local JSX stub, not a real framework runtime.
Accepted project
Create a fresh folder with exactly these files. Use TypeScript 5.8.3 and Node.js 22.16.0. Package stubs under node_modules are local teaching fixtures, not installed dependencies.
declare global {namespace JSX {interface Element{kind:string}}} function List<T>(p:{items:T[];render:(x:T)=>string}):JSX.Element{return {kind:p.items.map(p.render).join(",")};} const el=<List items={[1,2]} render={n=>n.toFixed(0)}/>;tsconfig.json
{ "compilerOptions": { "strict": true, "target": "ES2022", "module": "CommonJS", "moduleResolution": "Node10", "moduleDetection": "force", "skipLibCheck": true, "noEmitOnError": true, "types": [], "jsx": "preserve" }, "include": [ "**/*" ], "exclude": [ "node_modules", "dist", "build", "cache" ]}From the project root run: tsc -p tsconfig.json --pretty false.
Compilation succeeds (exit 0).
No runtime execution is required for this check.
Rejected project — diagnosis
Intentionally rejected variant. Do not execute it.
Use a fresh copy of the accepted project, changing only the files shown below.
declare global {namespace JSX {interface Element{kind:string}}} function List<T>(p:{items:T[];render:(x:T)=>string}):JSX.Element{return {kind:p.items.map(p.render).join(",")};} const el=<List items={[1,2]} render={n=>n.toUpperCase()}/>;From the project root run: tsc -p tsconfig.json --pretty false.
Expected compiler diagnostic: TS2339
No runtime execution is required for this check.
The callback receives a number, not a string. Restore the accepted configuration/source to compare the result.
Practice and recap
Use a list of objects and render a named property.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Generic and polymorphic props — knowledge check
Check the concept, interpret the tested project result, and diagnose a rejected configuration or source.
Which statement correctly describes Generic and polymorphic props?
Using the complete accepted project and the exact command in the lesson, which result is expected?
Why does the rejected project fail under its stated configuration?