คำถามติดแท็ก typescript2.0

2
Record type ใน typescript คืออะไร?
อะไร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 และประเภทสินค้าทุกประเภทหน้ากล่าวRecordภายใต้ประเภทแมปมุ่งหน้าไปข้างReadonly, PartialและPickในสิ่งที่ดูเหมือนจะเป็นความหมายของมัน type Record<K extends string, T> = { [P in K]: T; } อ่านอย่างเดียวบางส่วนและเลือกเป็น …

13
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" โดยปริยายมี type "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.