From dc72e8ed3bc4957a37ac8aa75ff4fd808031871d Mon Sep 17 00:00:00 2001 From: Yuichiro Tsuchiya Date: Fri, 11 Oct 2019 09:12:00 +0900 Subject: [PATCH] Fix @types/slate Data type definition to extend Immutable.Map, not Immutable.Record (#38772) --- types/slate/index.d.ts | 11 ++++++----- types/slate/slate-tests.ts | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/types/slate/index.d.ts b/types/slate/index.d.ts index ace0d0eae7..7b93e66314 100644 --- a/types/slate/index.d.ts +++ b/types/slate/index.d.ts @@ -12,17 +12,18 @@ // Benjamin Evenson // Han Jeon // Kay Delaney +// Yuichiro Tsuchiya // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 import * as Immutable from "immutable"; import { SyntheticEvent } from "react"; -export class Data extends Immutable.Record({}) { - [key: string]: any; +export interface Data extends Immutable.Map {} - static create(properties: Immutable.Map | { [key: string]: any }): Data; - static fromJSON(object: { [key: string]: any }): Data; - static fromJS(object: { [key: string]: any }): Data; +export namespace Data { + function create(properties: Immutable.Map | { [key: string]: any }): Data; + function fromJSON(object: { [key: string]: any }): Data; + function fromJS(object: { [key: string]: any }): Data; } export interface RulesByNodeType { diff --git a/types/slate/slate-tests.ts b/types/slate/slate-tests.ts index c04deb9603..9f1b483c81 100644 --- a/types/slate/slate-tests.ts +++ b/types/slate/slate-tests.ts @@ -22,6 +22,13 @@ import { import { List } from "immutable"; const data = Data.create({ foo: "bar " }); + +// $ExpectType any +data.get('hoge'); + +// $ExpectError +data['foo']; + const value = Value.create({ data }); const node: BlockJSON = {