Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Distribute 'keyof' intersection types#22300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ahejlsberg merged 4 commits intomasterfromdistributeKeyofIntersection
Mar 3, 2018

Conversation

@ahejlsberg
Copy link
Member

@ahejlsbergahejlsberg commentedMar 2, 2018
edited
Loading

With this PR we transformkeyof applied to an intersection type to a union ofkeyof applied to each intersection constituent. In other words, we rewrite types of the formkeyof (A & B) tokeyof A | keyof B.

Some examples:

typeA={a:string};typeB={b:string};typeT1=keyof(A&B);// "a" | "b"typeT2<T>=keyof(T&B);// keyof T | "b"typeT3<U>=keyof(A&U);// "a" | keyof UtypeT4<T,U>=keyof(T&U);// keyof T | keyof UtypeT5=T2<A>;// "a" | "b"typeT6=T3<B>;// "a" | "b"typeT7=T4<A,B>;// "a" | "b"

Fixes#22291.

kpdonn, karol-majewski, rubenlg, MCKanpolat, zpdDG4gta8XKpMCd, SlurpTheo, huy-nguyen, SalathielGenese, Igorbek, krishan, and 2 more reacted with hooray emojilierdakil reacted with heart emoji
@weswigham
Copy link
Member

keyof (string & {__brand: any}) and similar intersections needs tests documenting their behavior. (Other "empty" intersections likestring & number, too)

@ahejlsbergahejlsberg merged commit2d5be24 intomasterMar 3, 2018
@ahejlsbergahejlsberg deleted the distributeKeyofIntersection branchMarch 3, 2018 00:08
@Griffork
Copy link

Griffork commentedMar 5, 2018
edited
Loading

From#22286
Just downloaded the nightly, this doesn't work:

typeOptionalCommands<Cextendsstring,T>={[parameterinC]?:T};typeOptionalPropertyOrCommand<Cextendsstring,T>=Partial<T>&OptionalCommands<C,T>;
classThing<T>{thing:OptionalPropertyOrCommand<"this"|"that",T>;myfoo<VextendskeyofT>(property:V,newvalue:T[V]){this.thing[property]=newvalue;}myfoo2(newthing:T){this.thing["that"]=newthing;}}

EDIT: Was fixed, apparently nightlys aren't nightly.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@weswighamweswighamAwaiting requested review from weswigham

1 more reviewer

@mhegazymhegazymhegazy approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@ahejlsberg@weswigham@Griffork@mhegazy

[8]ページ先頭

©2009-2025 Movatter.jp