TypeScript/tests/cases/compiler/tsxInferenceShouldNotYieldAnyOnUnions.tsx
Wesley Wigham 009d9b4f22 For JSX Attributes, map over unions of props for contextual types (#17790)
* For JSX Attributes, allow attributes to fulfill the member of any union member; rather than all of them

* Use cached way of getting partial union members

* Reuse methodology used for object literals for jsx attributes

* Inline assignment

* Rename type
2017-08-22 14:13:56 -07:00

29 lines
789 B
TypeScript

// @jsx: preserve
// @filename: index.tsx
namespace JSX {
export interface Element {}
}
type Props<T> = PropsBase<string> | PropsWithConvert<T>;
interface PropsBase<T> {
data: T;
}
interface PropsWithConvert<T> extends PropsBase<T> {
convert: (t: T) => string;
}
function ShouldInferFromData<T>(props: Props<T>): JSX.Element {
return <div />;
}
// Sanity check: function call equivalent versions work fine
ShouldInferFromData({ data: "1" });
ShouldInferFromData({ data: "1", convert: n => "" + n });
ShouldInferFromData({ data: 2, convert: n => "" + n });
const f1 = <ShouldInferFromData data={"1"} />;
const f2 = <ShouldInferFromData data={"1"} convert={n => "" + n} />;
const f3 = <ShouldInferFromData data={2} convert={n => "" + n} />;