From 66d08e2f06fc28506c6d1a9e7fc86e524d43f0a3 Mon Sep 17 00:00:00 2001 From: Junyoung Choi Date: Mon, 26 Nov 2018 15:44:03 +0900 Subject: [PATCH] Include instruction how to extend vfiles --- types/vfile/readme.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 types/vfile/readme.md diff --git a/types/vfile/readme.md b/types/vfile/readme.md new file mode 100644 index 0000000000..349503cef8 --- /dev/null +++ b/types/vfile/readme.md @@ -0,0 +1,32 @@ +## VFile typescript Docs + +Below are some examples of how to use these Definitions.
+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({ + 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); +```