GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Can't remove optional modifier from properties on tree · Issue #24250 · microsoft/TypeScript Closed Labels QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code DescriptionTypeScript Version: 2.9.1-insiders.20180516 Search Terms: Code // Utility types type Entity<T> = T; type Eager<T> = { [P in keyof T]-?: T[P] extends Entity<infer U> ? Eager<U> : never; } & { [P in keyof T]: T[P] extends Entity<infer U> ? never : T[P]; } // Database models type Person = { firstName: string; lastName: string; addresses?: Entity<Address[]>; } type Address = { line1: string; town: string; telephoneLine: Entity<TelephoneLine>; } type TelephoneLine = { phoneNumber: string; features?: { hasBroadband: boolean; } } declare var person: Person; person.addresses[0] // EXPECTED - addresses is possibly undefined declare var eagerLoadedPerson: Eager<Person> eagerLoadedPerson.addresses[0].line1; // should work fine but doesn't eagerLoadedPerson.addresses[0].telephoneLine.phoneNumber; // should work fine but doesn't eagerLoadedPerson.addresses[0].telephoneLine.features.hasBroadband // EXPECTED - should give error because "features" is not an entity so the ? modifier should remain Expected behavior: Actual behavior: // Utility types type Entity<T> = T; type primitive = string | number | boolean | null | undefined; type Eager<T> = NonNullable<{ [P in keyof T]: T[P] extends primitive ? T[P] : Eager<T[P]>; }> Related issues What I'm trying to achieve Activity
MetadataMetadataAssigneesLabelsQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |