mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
add typings for @loadable/server
This commit is contained in:
parent
6a7deb65b8
commit
742f59c19a
86
types/loadable__server/index.d.ts
vendored
Normal file
86
types/loadable__server/index.d.ts
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
// Type definitions for @loadable/server 5.2
|
||||
// Project: https://github.com/smooth-code/loadable-components
|
||||
// Definitions by: Martynas Kadiša <https://github.com/martynaskadisa>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { ComponentType, ReactElement, Component } from 'react';
|
||||
|
||||
export type ChunkExtractorOptions = {
|
||||
/**
|
||||
* Webpack entrypoints to load (default to `["main"]`)
|
||||
*/
|
||||
entrypoints?: string | string[];
|
||||
/**
|
||||
* Optional output path (only for `requireEntrypoint`)
|
||||
*/
|
||||
outputPath?: string;
|
||||
} & ({
|
||||
/**
|
||||
* Stats file path generated using `@loadable/webpack-plugin`
|
||||
*/
|
||||
statsFile: string;
|
||||
} | {
|
||||
/**
|
||||
* Stats generated using `@loadable/webpack-plugin`.
|
||||
*/
|
||||
stats: object;
|
||||
});
|
||||
|
||||
/**
|
||||
* Used to collect chunks server-side and get them as script tags or script elements
|
||||
*/
|
||||
export class ChunkExtractor {
|
||||
constructor(options: ChunkExtractorOptions);
|
||||
|
||||
/**
|
||||
* Wrap your application in a `ChunkExtractorManager`
|
||||
*/
|
||||
collectChunks(
|
||||
/**
|
||||
* JSX element that will be wrapped in `ChunkExtractorManager`
|
||||
*/
|
||||
element: JSX.Element
|
||||
): JSX.Element;
|
||||
|
||||
/**
|
||||
* Require the entrypoint of your application as a commonjs module.
|
||||
*/
|
||||
requireEntrypoint(name?: string): { default: ComponentType };
|
||||
|
||||
/**
|
||||
* Get scripts as a string of `<script>` tags
|
||||
*/
|
||||
getScriptTags(): string[];
|
||||
|
||||
/**
|
||||
* Get scripts as an array of React `<script>` elements.
|
||||
*/
|
||||
getScriptElements(): Array<ReactElement<{}>>;
|
||||
|
||||
/**
|
||||
* Get "prefetch" and "preload" links as a string of `<link>` tags
|
||||
*/
|
||||
getLinkTags(): string[];
|
||||
|
||||
/**
|
||||
* Get "prefetch" and "preload" links as an array of React `<link>` elements
|
||||
*/
|
||||
getLinkElements(): Array<ReactElement<{}>>;
|
||||
|
||||
/**
|
||||
* Get style links as a string of `<link>` tags
|
||||
*/
|
||||
getStyleTags(): string[];
|
||||
|
||||
/**
|
||||
* Get style links as an array of React `<link>` elements
|
||||
*/
|
||||
getStyleElements(): Array<ReactElement<{}>>;
|
||||
}
|
||||
|
||||
export interface ChunkExtractorManagerProps {
|
||||
extractor: ChunkExtractor;
|
||||
}
|
||||
|
||||
export class ChunkExtractorManager extends Component<ChunkExtractorManagerProps> {}
|
||||
74
types/loadable__server/loadable__server-tests.tsx
Normal file
74
types/loadable__server/loadable__server-tests.tsx
Normal file
@ -0,0 +1,74 @@
|
||||
import * as React from 'react';
|
||||
import { ChunkExtractor } from '@loadable/server';
|
||||
|
||||
// Should be satisfied by `stats` or `statsFile`
|
||||
new ChunkExtractor({ stats: {} });
|
||||
new ChunkExtractor({ statsFile: './path/to/stats' });
|
||||
|
||||
const {
|
||||
collectChunks,
|
||||
getLinkElements,
|
||||
getLinkTags,
|
||||
getScriptElements,
|
||||
getScriptTags,
|
||||
getStyleElements,
|
||||
getStyleTags,
|
||||
requireEntrypoint
|
||||
} = new ChunkExtractor({ stats: {} });
|
||||
|
||||
// collectChunks
|
||||
{
|
||||
// Should accept jsx as first argument
|
||||
collectChunks(<div>Test</div>);
|
||||
|
||||
// Should return jsx
|
||||
const jsx: JSX.Element = collectChunks(<div>Test</div>);
|
||||
}
|
||||
|
||||
// getLinkElements
|
||||
{
|
||||
// Should return an array of React elements
|
||||
const elements: Array<React.ReactElement<{}>> = getLinkElements();
|
||||
}
|
||||
|
||||
// getLinkTags
|
||||
{
|
||||
// Should return an arary of strings
|
||||
const tags: string[] = getLinkTags();
|
||||
}
|
||||
|
||||
// getScriptElements
|
||||
{
|
||||
// Should return an array of React elements
|
||||
const elements: Array<React.ReactElement<{}>> = getScriptElements();
|
||||
}
|
||||
|
||||
// getScriptTags
|
||||
{
|
||||
// Should return an arary of strings
|
||||
const tags: string[] = getScriptTags();
|
||||
}
|
||||
|
||||
// getStyleElements
|
||||
{
|
||||
// Should return an array of React elements
|
||||
const elements: Array<React.ReactElement<{}>> = getStyleElements();
|
||||
}
|
||||
|
||||
// getStyleTags
|
||||
{
|
||||
// Should return an arary of strings
|
||||
const tags: string[] = getStyleTags();
|
||||
}
|
||||
|
||||
// requireEntrypoint
|
||||
{
|
||||
// Should work without params
|
||||
requireEntrypoint();
|
||||
|
||||
// Should accept string
|
||||
requireEntrypoint('main');
|
||||
|
||||
// Should return component on default property
|
||||
const entry: { default: React.ComponentType } = requireEntrypoint();
|
||||
}
|
||||
29
types/loadable__server/tsconfig.json
Normal file
29
types/loadable__server/tsconfig.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"jsx": "react",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@loadable/server": [
|
||||
"loadable__server"
|
||||
]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"loadable__server-tests.tsx"
|
||||
]
|
||||
}
|
||||
1
types/loadable__server/tslint.json
Normal file
1
types/loadable__server/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user