-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not expand type references in keyof and index access #58715
Merged
weswigham
merged 3 commits into
microsoft:main
from
bloomberg:do-not-inline-types-aliases
May 31, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
3928d9b
Do not expand type references in index access types and when used wit…
dragomirtitian c5d6841
Merge remote-tracking branch 'remotes/origin/main' into do-not-inline…
dragomirtitian 96f5b35
Use new fallback to print inferred type when reusing existing type no…
dragomirtitian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
tests/baselines/reference/declarationEmitAliasInlineing.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//// [tests/cases/compiler/declarationEmitAliasInlineing.ts] //// | ||
|
||
//// [a.ts] | ||
type O = { | ||
prop: string | ||
prop2: string | ||
} | ||
|
||
type I = { | ||
prop: string | ||
} | ||
|
||
export const fn = (v: O['prop'], p: Omit<O, 'prop'>, key: keyof O, p2: Omit<O, keyof I>) => {}; | ||
|
||
//// [aExp.ts] | ||
export type O = { | ||
prop: string | ||
prop2: string | ||
} | ||
|
||
export type I = { | ||
prop: string | ||
} | ||
|
||
export const fnExp = (v: O['prop'], p: Omit<O, 'prop'>, key: keyof O, p2: Omit<O, keyof I>) => {}; | ||
|
||
//// [b.ts] | ||
import {fn} from './a' | ||
import {fnExp} from './aExp' | ||
export const f = fn; | ||
export const fExp = fnExp; | ||
|
||
//// [a.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fn = void 0; | ||
var fn = function (v, p, key, p2) { }; | ||
exports.fn = fn; | ||
//// [aExp.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fnExp = void 0; | ||
var fnExp = function (v, p, key, p2) { }; | ||
exports.fnExp = fnExp; | ||
//// [b.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fExp = exports.f = void 0; | ||
var a_1 = require("./a"); | ||
var aExp_1 = require("./aExp"); | ||
exports.f = a_1.fn; | ||
exports.fExp = aExp_1.fnExp; | ||
|
||
|
||
//// [a.d.ts] | ||
type O = { | ||
prop: string; | ||
prop2: string; | ||
}; | ||
type I = { | ||
prop: string; | ||
}; | ||
export declare const fn: (v: O["prop"], p: Omit<O, "prop">, key: keyof O, p2: Omit<O, keyof I>) => void; | ||
export {}; | ||
//// [aExp.d.ts] | ||
export type O = { | ||
prop: string; | ||
prop2: string; | ||
}; | ||
export type I = { | ||
prop: string; | ||
}; | ||
export declare const fnExp: (v: O["prop"], p: Omit<O, "prop">, key: keyof O, p2: Omit<O, keyof I>) => void; | ||
//// [b.d.ts] | ||
export declare const f: (v: string, p: Omit<{ | ||
prop: string; | ||
prop2: string; | ||
}, "prop">, key: keyof { | ||
prop: string; | ||
prop2: string; | ||
}, p2: Omit<{ | ||
prop: string; | ||
prop2: string; | ||
}, "prop">) => void; | ||
export declare const fExp: (v: import("./aExp").O["prop"], p: Omit<import("./aExp").O, "prop">, key: keyof import("./aExp").O, p2: Omit<import("./aExp").O, keyof import("./aExp").I>) => void; |
81 changes: 81 additions & 0 deletions
81
tests/baselines/reference/declarationEmitAliasInlineing.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//// [tests/cases/compiler/declarationEmitAliasInlineing.ts] //// | ||
|
||
=== a.ts === | ||
type O = { | ||
>O : Symbol(O, Decl(a.ts, 0, 0)) | ||
|
||
prop: string | ||
>prop : Symbol(prop, Decl(a.ts, 0, 10)) | ||
|
||
prop2: string | ||
>prop2 : Symbol(prop2, Decl(a.ts, 1, 16)) | ||
} | ||
|
||
type I = { | ||
>I : Symbol(I, Decl(a.ts, 3, 1)) | ||
|
||
prop: string | ||
>prop : Symbol(prop, Decl(a.ts, 5, 10)) | ||
} | ||
|
||
export const fn = (v: O['prop'], p: Omit<O, 'prop'>, key: keyof O, p2: Omit<O, keyof I>) => {}; | ||
>fn : Symbol(fn, Decl(a.ts, 9, 12)) | ||
>v : Symbol(v, Decl(a.ts, 9, 19)) | ||
>O : Symbol(O, Decl(a.ts, 0, 0)) | ||
>p : Symbol(p, Decl(a.ts, 9, 32)) | ||
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) | ||
>O : Symbol(O, Decl(a.ts, 0, 0)) | ||
>key : Symbol(key, Decl(a.ts, 9, 52)) | ||
>O : Symbol(O, Decl(a.ts, 0, 0)) | ||
>p2 : Symbol(p2, Decl(a.ts, 9, 66)) | ||
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) | ||
>O : Symbol(O, Decl(a.ts, 0, 0)) | ||
>I : Symbol(I, Decl(a.ts, 3, 1)) | ||
|
||
=== aExp.ts === | ||
export type O = { | ||
>O : Symbol(O, Decl(aExp.ts, 0, 0)) | ||
|
||
prop: string | ||
>prop : Symbol(prop, Decl(aExp.ts, 0, 17)) | ||
|
||
prop2: string | ||
>prop2 : Symbol(prop2, Decl(aExp.ts, 1, 16)) | ||
} | ||
|
||
export type I = { | ||
>I : Symbol(I, Decl(aExp.ts, 3, 1)) | ||
|
||
prop: string | ||
>prop : Symbol(prop, Decl(aExp.ts, 5, 17)) | ||
} | ||
|
||
export const fnExp = (v: O['prop'], p: Omit<O, 'prop'>, key: keyof O, p2: Omit<O, keyof I>) => {}; | ||
>fnExp : Symbol(fnExp, Decl(aExp.ts, 9, 12)) | ||
>v : Symbol(v, Decl(aExp.ts, 9, 22)) | ||
>O : Symbol(O, Decl(aExp.ts, 0, 0)) | ||
>p : Symbol(p, Decl(aExp.ts, 9, 35)) | ||
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) | ||
>O : Symbol(O, Decl(aExp.ts, 0, 0)) | ||
>key : Symbol(key, Decl(aExp.ts, 9, 55)) | ||
>O : Symbol(O, Decl(aExp.ts, 0, 0)) | ||
>p2 : Symbol(p2, Decl(aExp.ts, 9, 69)) | ||
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) | ||
>O : Symbol(O, Decl(aExp.ts, 0, 0)) | ||
>I : Symbol(I, Decl(aExp.ts, 3, 1)) | ||
|
||
=== b.ts === | ||
import {fn} from './a' | ||
>fn : Symbol(fn, Decl(b.ts, 0, 8)) | ||
|
||
import {fnExp} from './aExp' | ||
>fnExp : Symbol(fnExp, Decl(b.ts, 1, 8)) | ||
|
||
export const f = fn; | ||
>f : Symbol(f, Decl(b.ts, 2, 12)) | ||
>fn : Symbol(fn, Decl(b.ts, 0, 8)) | ||
|
||
export const fExp = fnExp; | ||
>fExp : Symbol(fExp, Decl(b.ts, 3, 12)) | ||
>fnExp : Symbol(fnExp, Decl(b.ts, 1, 8)) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised we don't emit this as
since we're willing to emit the
import("./aExp").O["prop"]
et al.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeof
is currently only used for function declarations. I think leaning intotypeof
for variables is an options that should be considered. I'm not sure why only function declarations usetypeof
(although I haven't really though too deeply about it)