This commit changes the index.ts file auto-generated in the src directory to export all exportable declarations from the component.d.ts file. This makes for a better developer experience as all types will be automatically exported from the root of output target directories (e.g. custom event types)
Changed behavior
With this change, everything marked as export from the component.d.ts file will now be exported from the index.ts file. This continues to include the Components and JSX definitions that were previously exported by name. But, this will now also include any custom events and (soon) types used as a part of custom events.
For instance, if there is a Stencil component with an @Event() output:
export type MyCustomEventType = {
name: string;
value: number;
}
@Component({
tag: 'my-component',
styleUrl: 'my-component.css',
shadow: true,
})
export class MyComponent {
@Event() myEvent: EventEmitter<MyCustomEventType>:
// All your other component stuff here
}
The component.d.ts file would generate type definitions such as:
This type will now be re-exported by the barrel file. In addition, once this PR is merged, the component.d.ts file will also re-export the custom event types used in component event emitter definitions so consuming applications can easily use them to define expected metadata structure. So, the index.ts file will then also export those types.
Testing
Pull/fork this code to be used as a Stencil project (this is essentially what the "create Stencil" CLI app does when choosing a component starter).
Modify the MyComponent component to include an @Event()definition.
Build the project and verify the contents of dist/types/index.ts is export * from './components';
Locally package the build and consume in a separate project.
Verify Components, JSX, and MyComponentCustomEvent can all be imported from the package types (i.e. something like import { Components, JSX, MyComponentCustomEvent} from '@my-test-package/types';)
This commit changes the
index.ts
file auto-generated in thesrc
directory to export all exportable declarations from thecomponent.d.ts
file. This makes for a better developer experience as all types will be automatically exported from the root of output target directories (e.g. custom event types)Changed behavior
With this change, everything marked as
export
from thecomponent.d.ts
file will now be exported from theindex.ts
file. This continues to include theComponents
andJSX
definitions that were previously exported by name. But, this will now also include any custom events and (soon) types used as a part of custom events.For instance, if there is a Stencil component with an
@Event()
output:The
component.d.ts
file would generate type definitions such as:This type will now be re-exported by the barrel file. In addition, once this PR is merged, the
component.d.ts
file will also re-export the custom event types used in component event emitter definitions so consuming applications can easily use them to define expected metadata structure. So, theindex.ts
file will then also export those types.Testing
MyComponent
component to include an@Event()
definition.dist/types/index.ts
isexport * from './components';
Components
,JSX
, andMyComponentCustomEvent
can all be imported from the package types (i.e. something likeimport { Components, JSX, MyComponentCustomEvent} from '@my-test-package/types';
)