mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Fix rollback Node
Position is not supposed to be extensible, but Node is. Testing cases for this are also added.
This commit is contained in:
Vendored
+7
-3
@@ -18,6 +18,10 @@ declare namespace vfile {
|
||||
end: Point;
|
||||
}
|
||||
|
||||
interface Node {
|
||||
position: Position;
|
||||
}
|
||||
|
||||
interface VFileParamsBase<D> {
|
||||
data?: D;
|
||||
contents?: Contents;
|
||||
@@ -43,11 +47,11 @@ declare namespace vfile {
|
||||
fatal?: boolean | null;
|
||||
}
|
||||
|
||||
type Message = <P extends Position>(reason: string, position?: Point | P, ruleId?: string) => VFileError;
|
||||
type Message = <N extends Node>(reason: string, position?: Point | Position | N, ruleId?: string) => VFileError;
|
||||
|
||||
type Fail = <P extends Position>(reason: string, position?: Point | P, ruleId?: string) => never;
|
||||
type Fail = <N extends Node>(reason: string, position?: Point | Position | N, ruleId?: string) => never;
|
||||
|
||||
type Info = <P extends Position>(reason: string, position?: Point | P, ruleId?: string) => void;
|
||||
type Info = <N extends Node>(reason: string, position?: Point | Position | N, ruleId?: string) => void;
|
||||
|
||||
type ToString = (encoding?: BufferEncoding) => string;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import vfile = require("vfile");
|
||||
import { Point, Position } from "vfile";
|
||||
|
||||
const file = vfile({
|
||||
path: '~/example.txt',
|
||||
@@ -28,5 +29,28 @@ console.log(file.messages);
|
||||
const custom: string = file.custom; // 'Custom tango'
|
||||
const dataCustom: number = file.data.custom; // 12345
|
||||
|
||||
// message method accept any Stringifiable Position(e.g. point, position, node with position)
|
||||
const startPoint: Point = {
|
||||
line: 1,
|
||||
column: 1,
|
||||
};
|
||||
const position: Position = {
|
||||
start: startPoint,
|
||||
end: {
|
||||
line: 2,
|
||||
column: 2,
|
||||
}
|
||||
};
|
||||
// Accept Point
|
||||
file.message('test', position);
|
||||
// Accept Position
|
||||
file.message('test', position);
|
||||
// Accept Node with extra value
|
||||
file.message('test', {
|
||||
position
|
||||
});
|
||||
// But, it must reject any malformed position
|
||||
file.message({ start: 'invalid point' }); // $ExpectError
|
||||
|
||||
// Typings of original properties must be kept
|
||||
const fileWithWrongParams = vfile({ path: 1234 }); // $ExpectError
|
||||
|
||||
Reference in New Issue
Block a user