mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Add decription for data prop
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user