Skip to content

Fix: implement circularBuffer type checks #480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/node_modules/@stdlib/utils/circular-buffer/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,40 @@ import CircularBuffer = require( './index' );
// The function returns a circular buffer instance...
{
new CircularBuffer( 3 ); // $ExpectType CircularBuffer
new CircularBuffer( [2, 3] ); // $ExpectType CircularBuffer
}

// The functions or fields of instance should be ok
{
const buf = new CircularBuffer( 3 ); // $ExpectType CircularBuffer
buf.push( 'foo' );
let circularBuf: CircularBuffer;
let numberType: number;
let booleanType: boolean;
let stringType: string;
let arrayType: any[];

numberType = buf.count;
numberType = buf.length;
booleanType = buf.full;
circularBuf = buf.clear();
stringType = buf.toJSON();
arrayType = buf.toArray();
}

// The compiler throws an error if the constructor function is provided an invalid number of arguments...
{
new CircularBuffer(); // $ExpectError
new CircularBuffer( 3, 4 ); // $ExpectError
}

// The compiler throws an error if the constructor is provided an invalid argument type...
{
new CircularBuffer( 'invalidType' ); // $ExpectError
new CircularBuffer( 12.2 ); // $ExpectError
new CircularBuffer( {} ); // $ExpectError
new CircularBuffer( true ); // $ExpectError
new CircularBuffer( null ); // $ExpectError
new CircularBuffer( undefined ); // $ExpectError
new CircularBuffer( new Date() ); // $ExpectError
}