-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from lume/update-jsx-type-helpers
**feat:** improve the `ElementAttributes` and `ReactElementAttributes` JSX type helpers.
- Loading branch information
Showing
18 changed files
with
356 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { ReactElementAttributes } from './react.js'; | ||
declare class SomeElement extends HTMLElement { | ||
someProp: 'true' | 'false' | boolean; | ||
get otherProp(): number; | ||
set otherProp(_: this['__set__otherProp']); | ||
/** do not use this property, its only for JSX types */ | ||
__set__otherProp: number | 'foo'; | ||
} | ||
declare module 'react' { | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
'some-element': ReactElementAttributes<SomeElement, 'someProp' | 'otherProp'>; | ||
} | ||
} | ||
} | ||
export {}; | ||
//# sourceMappingURL=jsx-types-react.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* @jsxImportSource react */ | ||
class SomeElement extends HTMLElement { | ||
someProp = true; | ||
get otherProp() { | ||
return 0; | ||
} | ||
set otherProp(_) { } | ||
/** do not use this property, its only for JSX types */ | ||
__set__otherProp; | ||
} | ||
SomeElement; | ||
describe('JSX types with ReactElementAttributes', () => { | ||
it('derives JSX types from classes', () => { | ||
; | ||
<> | ||
<some-element someProp="false" otherProp="foo"/> | ||
<some-element someProp="false" otherProp="foo"/> | ||
<some-element someProp={false} otherProp={123}/> | ||
{/* @ts-expect-error good, number is invalid */} | ||
<some-element someProp={123}/> | ||
{/* @ts-expect-error good, 'blah' is invalid */} | ||
<some-element otherProp="blah"/> | ||
|
||
{/* Additionally TypeScript will allow unknown dash-case props (as we didn't not define JS properties with these exact dash-cased names, React 19+ will set the element attributes, useful for setting the attributes but React has no way to specify to set attributes for names without dashes) */} | ||
<some-element some-prop="false" other-prop="foo"/> | ||
{/* @ts-expect-error foo doesn't exist. TypeScript will only check existence of properties without dashes */} | ||
<some-element foo="false"/> | ||
</>; | ||
}); | ||
}); | ||
export {}; | ||
//# sourceMappingURL=jsx-types-react.test.jsx.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { ElementAttributes } from './LumeElement.js'; | ||
declare class SomeElement extends HTMLElement { | ||
someProp: 'true' | 'false' | boolean; | ||
get otherProp(): number; | ||
set otherProp(_: this['__set__otherProp']); | ||
/** do not use this property, its only for JSX types */ | ||
__set__otherProp: number | 'foo'; | ||
} | ||
declare module 'solid-js' { | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
'some-element': ElementAttributes<SomeElement, 'someProp' | 'otherProp'>; | ||
} | ||
} | ||
} | ||
export {}; | ||
//# sourceMappingURL=jsx-types-solid.test.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* @jsxImportSource solid-js */ | ||
class SomeElement extends HTMLElement { | ||
someProp = true; | ||
get otherProp() { | ||
return 0; | ||
} | ||
set otherProp(_) { } | ||
/** do not use this property, its only for JSX types */ | ||
__set__otherProp; | ||
} | ||
SomeElement; | ||
describe('JSX types with ElementAttributes', () => { | ||
it('derives JSX types from classes', () => { | ||
; | ||
<> | ||
<some-element some-prop="false" other-prop="foo"/> | ||
<some-element some-prop="false" other-prop="foo"/> | ||
<some-element some-prop={false} other-prop={123}/> | ||
{/* @ts-expect-error good, number is invalid */} | ||
<some-element some-prop={123}/> | ||
{/* @ts-expect-error good, 'blah' is invalid */} | ||
<some-element other-prop="blah"/> | ||
|
||
{/* Additionally TypeScript will allow unknown dash-case props (the attr: can be used here to tell Solid to set the element attributes instead of the JS properties) */} | ||
<some-element attr:some-prop="false" attr:other-prop="foo"/> | ||
{/* @ts-expect-error foo doesn't exist. TypeScript will only check existence of properties without dashes */} | ||
<some-element foo="false"/> | ||
</>; | ||
}); | ||
}); | ||
export {}; | ||
//# sourceMappingURL=jsx-types-solid.test.jsx.map |
Oops, something went wrong.