タグ付けされた質問 「typescript2.0」

2
typescriptのRecordタイプとは何ですか?
Record<K, T>Typescript とはどういう意味ですか? Typescript 2.1はRecordタイプを導入し、例でそれを説明しました: // For every properties K of type T, transform it to U function mapObject<K extends string, T, U>(obj: Record<K, T>, f: (x: T) => U): Record<K, U> Typescript 2.1を参照 また、[ Advanced Types]ページではRecord、マップされたタイプの見出しの下に、その定義のように見えるもので、、、およびの横Readonlyに言及しています。PartialPick type Record<K extends string, T> = { [P in K]: T; } Readonly、Partial、Pickは準同型ですが、Recordは同型ではありません。Recordが準同型ではないことの1つの手掛かりは、プロパティをコピーするために入力タイプをとらないことです。 …

12
TypeScriptとReact-子供のタイプ?
次のような非常にシンプルな機能コンポーネントがあります。 import * as React from 'react'; export interface AuxProps { children: React.ReactNode } const aux = (props: AuxProps) => props.children; export default aux; そして別のコンポーネント: import * as React from "react"; export interface LayoutProps { children: React.ReactNode } const layout = (props: LayoutProps) => ( <Aux> <div>Toolbar, SideDrawer, Backdrop</div> <main> …

1
型注釈がないため、 'this'は暗黙的に型 'any'を持ちます
で有効にするnoImplicitThisとtsconfig.json、次のコードでこのエラーが発生します。 'this' implicitly has type 'any' because it does not have a type annotation. class Foo implements EventEmitter { on(name: string, fn: Function) { } emit(name: string) { } } const foo = new Foo(); foo.on('error', function(err: any) { console.log(err); this.emit('end'); // error: `this` implicitly has type `any` }); 型指定thisをコールバックパラメータに追加すると、同じエラーが発生します。 …
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.