[unist]: add types (#19472)

This commit is contained in:
bizen241 2017-08-31 09:02:59 +09:00 committed by Mohamed Hegazy
parent 0f62f0016e
commit ac52d79dde
4 changed files with 111 additions and 0 deletions

39
types/unist/index.d.ts vendored Normal file
View File

@ -0,0 +1,39 @@
// Type definitions for Unist 1.0
// Project: https://github.com/syntax-tree/unist
// Definitions by: bizen241 <https://github.com/bizen241>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
export interface Node {
type: string;
data?: Data;
position?: Position;
}
export interface Data {
[key: string]: string | number | object | any[] | boolean | null;
}
export interface Position {
start: Point;
end: Point;
/** >= 1 */
indent?: number[];
}
export interface Point {
/** >= 1 */
line: number;
/** >= 1 */
column: number;
/** >= 0 */
offset?: number;
}
export interface Parent extends Node {
children: Node[];
}
export interface Text extends Node {
value: string;
}

22
types/unist/tsconfig.json Normal file
View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"unist-tests.ts"
]
}

1
types/unist/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@ -0,0 +1,49 @@
import * as Unist from 'unist';
const data: Unist.Data = {
string: 'string',
number: 1,
object: {
key: 'value',
},
array: [],
boolean: true,
null: null,
};
const point: Unist.Point = {
line: 1,
column: 1,
offset: 0,
};
const position: Unist.Position = {
start: point,
end: point,
indent: [
1,
],
};
const node: Unist.Node = {
type: 'node',
data,
position,
};
const text: Unist.Text = {
type: 'text',
data,
position,
value: 'value',
};
const parent: Unist.Parent = {
type: 'parent',
data,
position,
children: [
node,
text,
],
};