Include instruction how to extend vfiles

This commit is contained in:
Junyoung Choi
2018-11-26 15:44:03 +09:00
parent bcd33769d5
commit 66d08e2f06
+32
View File
@@ -0,0 +1,32 @@
## VFile typescript Docs
Below are some examples of how to use these Definitions.<br>
Scenarios where the Typescript code is identical to plain Javascript code are omitted.
### Extending VFile
```ts
import vfile = require('vfile')
// 1. Define extended vfile interface
interface CustomVFile extends vfile.VFile {
custom: string;
data: {
custom: number;
};
}
// 2. Provide the extended interface to generic type parameter
// So it can be used for return value
const file: CustomVFile = vfile<CustomVFile>({
path: '~/example.txt',
contents: 'Alpha *braavo* charlie.',
custom: 'Custom tango',
data: {
custom: 12345
}
});
// vfile recognize extended VFile values. So it will return same type.
const copiedFile: CustomVFile = vfile(file);
```