Add decription for data prop

This commit is contained in:
Junyoung Choi
2018-11-27 14:47:42 +09:00
parent 1da614b335
commit dcf5a0dbd4
+28
View File
@@ -3,6 +3,34 @@
Below are some examples of how to use these Definitions.<br>
Scenarios where the Typescript code is identical to plain Javascript code are omitted.
### Using `data` property
Because `data` property type is set `unknown`, you have to make your own type guard.
```ts
interface CustomData {
message: string;
}
// This is the type guard
function isCustomData(data: any): data is CustomData {
return data != null && typeof data.message === 'string';
}
function doSomethingWithCustomData(data: CustomData) {
}
const customData: CustomData = {
message: 'tango'
};
const fileWithData = vfile({
data: customData
});
if (isCustomData(fileWithData.data)) {
doSomethingWithCustomData(fileWithData.data);
}
// The below code will throw a compiler error
doSomethingWithCustomData(fileWithData.data); // $ExpectError
```
### Extending VFile
```ts