From 545ee9c7869a6be3481ab3d92ad097c1bbfaa606 Mon Sep 17 00:00:00 2001 From: AntoineDoubovetzky Date: Sun, 17 Mar 2019 12:03:35 +0100 Subject: [PATCH 1/3] create react-scrollable-anchor package --- types/react-scrollable-anchor/index.d.ts | 26 ++++++++++ .../react-scrollable-anchor-tests.tsx | 47 +++++++++++++++++++ types/react-scrollable-anchor/tsconfig.json | 24 ++++++++++ types/react-scrollable-anchor/tslint.json | 1 + 4 files changed, 98 insertions(+) create mode 100644 types/react-scrollable-anchor/index.d.ts create mode 100644 types/react-scrollable-anchor/react-scrollable-anchor-tests.tsx create mode 100644 types/react-scrollable-anchor/tsconfig.json create mode 100644 types/react-scrollable-anchor/tslint.json diff --git a/types/react-scrollable-anchor/index.d.ts b/types/react-scrollable-anchor/index.d.ts new file mode 100644 index 0000000000..9459918b15 --- /dev/null +++ b/types/react-scrollable-anchor/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for react-scrollable-anchor 0.6 +// Project: https://github.com/gabergg/react-scrollable-anchor +// Definitions by: Antoine DOUBOVETZKY +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as React from 'react'; + +export interface ScrollableAnchorProps { + id: string; + children?: React.ReactNode; +} + +declare const ScrollableAnchor: React.ComponentType; + +export interface ConfigureAnchorsOptions { + offset?: number; + scrollDuration?: number; + keepLastAnchorHash?: boolean; +} + +export default ScrollableAnchor; +export function goToTop(): void; +export function configureAnchors(options: ConfigureAnchorsOptions): void; +export function goToAnchor(anchorId: string, saveHashUpdate?: boolean): void; +export function removeHash(): void; diff --git a/types/react-scrollable-anchor/react-scrollable-anchor-tests.tsx b/types/react-scrollable-anchor/react-scrollable-anchor-tests.tsx new file mode 100644 index 0000000000..984a01f741 --- /dev/null +++ b/types/react-scrollable-anchor/react-scrollable-anchor-tests.tsx @@ -0,0 +1,47 @@ +import * as React from 'react'; +import ScrollableAnchor, { goToAnchor, goToTop, removeHash, configureAnchors } from "react-scrollable-anchor"; + +/* + * goToAnchor + */ +// $ExpectType void +goToAnchor("one"); +// $ExpectError +goToAnchor(1); + +/* + * goToTop + */ +// $ExpectType void +goToTop(); +// $ExpectError +goToTop(1); + +/* + * removeHash + */ +// $ExpectType void +removeHash(); +// $ExpectError +removeHash(1); + +/* + * configureAnchors + */ +// $ExpectType void +configureAnchors({ offset: 500, scrollDuration: 1000, keepLastAnchorHash: true }); +// $ExpectError +configureAnchors(); +// $ExpectError +configureAnchors({ wrongKey: 1 }); +// $ExpectError +configureAnchors({ offset: 'string' }); +// $ExpectError +configureAnchors({ scrollDuration: 'string' }); +// $ExpectError +configureAnchors({ keepLastAnchorHash: 3 }); + +// $ExpectError +
Test
; + +
Test
; diff --git a/types/react-scrollable-anchor/tsconfig.json b/types/react-scrollable-anchor/tsconfig.json new file mode 100644 index 0000000000..198bad7412 --- /dev/null +++ b/types/react-scrollable-anchor/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "jsx": "react", + "noImplicitAny": true, + "strictFunctionTypes": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-scrollable-anchor-tests.tsx" + ] +} diff --git a/types/react-scrollable-anchor/tslint.json b/types/react-scrollable-anchor/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-scrollable-anchor/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 1f5666e4e012bc7e96a881a1f74a8b846bd0ae72 Mon Sep 17 00:00:00 2001 From: AntoineDoubovetzky Date: Tue, 19 Mar 2019 11:57:46 +0100 Subject: [PATCH 2/3] update default import --- types/react-scrollable-anchor/index.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/react-scrollable-anchor/index.d.ts b/types/react-scrollable-anchor/index.d.ts index 9459918b15..234c6db9c0 100644 --- a/types/react-scrollable-anchor/index.d.ts +++ b/types/react-scrollable-anchor/index.d.ts @@ -11,7 +11,6 @@ export interface ScrollableAnchorProps { children?: React.ReactNode; } -declare const ScrollableAnchor: React.ComponentType; export interface ConfigureAnchorsOptions { offset?: number; @@ -19,7 +18,7 @@ export interface ConfigureAnchorsOptions { keepLastAnchorHash?: boolean; } -export default ScrollableAnchor; +export default class ScrollableAnchor extends React.Component { } export function goToTop(): void; export function configureAnchors(options: ConfigureAnchorsOptions): void; export function goToAnchor(anchorId: string, saveHashUpdate?: boolean): void; From 5e4e3674a18da019f21a14d349f83d6b558ef9c2 Mon Sep 17 00:00:00 2001 From: AntoineDoubovetzky Date: Tue, 19 Mar 2019 15:02:36 +0100 Subject: [PATCH 3/3] remove consecutive blank line --- types/react-scrollable-anchor/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/react-scrollable-anchor/index.d.ts b/types/react-scrollable-anchor/index.d.ts index 234c6db9c0..ea495dd0f7 100644 --- a/types/react-scrollable-anchor/index.d.ts +++ b/types/react-scrollable-anchor/index.d.ts @@ -11,7 +11,6 @@ export interface ScrollableAnchorProps { children?: React.ReactNode; } - export interface ConfigureAnchorsOptions { offset?: number; scrollDuration?: number;