-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Ensure parameters are in scope when converting parameter/return types to type nodes #49627
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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
170 changes: 170 additions & 0 deletions
170
tests/baselines/reference/declarationEmitGlobalThisPreserved.js
This file contains hidden or 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,170 @@ | ||
//// [declarationEmitGlobalThisPreserved.ts] | ||
// Adding this makes tooltips fail too. | ||
// declare global { | ||
// namespace isNaN { | ||
// const prop: number; | ||
// } | ||
// } | ||
|
||
// Broken inference cases. | ||
|
||
export const a1 = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN; | ||
export const a2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN; | ||
export const a3 = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar; | ||
export const a4 = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN; | ||
|
||
export const aObj = { | ||
a1: (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN, | ||
a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN, | ||
a3: (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar, | ||
a4: (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN, | ||
} | ||
|
||
export type a4Return = ReturnType<ReturnType<typeof a4>>; | ||
export type a4oReturn = ReturnType<ReturnType<typeof aObj['a4']>>; | ||
|
||
export const b1 = (isNaN: typeof globalThis.isNaN) => isNaN; | ||
export const b2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN; | ||
export const b3 = (isNaN: number, bar: typeof globalThis.isNaN) => bar; | ||
export const b4 = (isNaN: number) => globalThis.isNaN; | ||
|
||
export const bObj = { | ||
b1: (isNaN: typeof globalThis.isNaN) => isNaN, | ||
b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN, | ||
b3: (isNaN: number, bar: typeof globalThis.isNaN) => bar, | ||
b4: (isNaN: number) => globalThis.isNaN, | ||
} | ||
|
||
export type b4Return = ReturnType<ReturnType<typeof b4>>; | ||
export type b4oReturn = ReturnType<ReturnType<typeof bObj['b4']>>; | ||
|
||
export function c1(isNaN: typeof globalThis.isNaN) { return isNaN } | ||
export function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN } | ||
export function c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar } | ||
export function c4(isNaN: number) { return globalThis.isNaN; } | ||
|
||
export const cObj = { | ||
c1(isNaN: typeof globalThis.isNaN) { return isNaN }, | ||
c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN }, | ||
c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar }, | ||
c4(isNaN: number) { return globalThis.isNaN; }, | ||
} | ||
|
||
export type c4Return = ReturnType<ReturnType<typeof c4>>; | ||
export type c4oReturn = ReturnType<ReturnType<typeof cObj['c4']>>; | ||
|
||
export function d1() { | ||
const fn = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN; | ||
return function() { return fn }; | ||
} | ||
|
||
export function d2() { | ||
const fn = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN; | ||
return function() { return fn }; | ||
} | ||
|
||
export function d3() { | ||
const fn = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar; | ||
return function() { return fn }; | ||
} | ||
|
||
export function d4() { | ||
const fn = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN; | ||
return function() { return fn }; | ||
} | ||
|
||
export type d4Return = ReturnType<ReturnType<ReturnType<ReturnType<typeof d4>>>>; | ||
|
||
export class A { | ||
method1(isNaN: typeof globalThis.isNaN) { return isNaN } | ||
method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN } | ||
method3(isNaN: number, bar: typeof globalThis.isNaN) { return bar } | ||
method4(isNaN: number) { return globalThis.isNaN; } | ||
} | ||
|
||
export function fromParameter(isNaN: number, bar: typeof globalThis.isNaN) { | ||
return function() { return { bar } }; | ||
} | ||
|
||
// Non-inference cases. | ||
|
||
export const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN = (isNaN) => isNaN; | ||
|
||
export function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN { | ||
return isNaN; | ||
}; | ||
|
||
export type AsObjectProperty = { | ||
isNaN: typeof globalThis.isNaN; | ||
} | ||
|
||
export class AsClassProperty { | ||
isNaN?: typeof globalThis.isNaN; | ||
} | ||
|
||
export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
|
||
|
||
|
||
|
||
|
||
//// [declarationEmitGlobalThisPreserved.d.ts] | ||
export declare const a1: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
export declare const a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
export declare const a3: (isNaN: number, bar: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
export declare const a4: (isNaN: number) => typeof globalThis.isNaN; | ||
export declare const aObj: { | ||
a1: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
a3: (isNaN: number, bar: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
a4: (isNaN: number) => typeof globalThis.isNaN; | ||
}; | ||
export type a4Return = ReturnType<ReturnType<typeof a4>>; | ||
export type a4oReturn = ReturnType<ReturnType<typeof aObj['a4']>>; | ||
export declare const b1: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
export declare const b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
export declare const b3: (isNaN: number, bar: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
export declare const b4: (isNaN: number) => typeof globalThis.isNaN; | ||
export declare const bObj: { | ||
b1: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
b3: (isNaN: number, bar: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
b4: (isNaN: number) => typeof globalThis.isNaN; | ||
}; | ||
export type b4Return = ReturnType<ReturnType<typeof b4>>; | ||
export type b4oReturn = ReturnType<ReturnType<typeof bObj['b4']>>; | ||
export declare function c1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; | ||
export declare function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN; | ||
export declare function c3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; | ||
export declare function c4(isNaN: number): typeof globalThis.isNaN; | ||
export declare const cObj: { | ||
c1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; | ||
c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN; | ||
c3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; | ||
c4(isNaN: number): typeof globalThis.isNaN; | ||
}; | ||
export type c4Return = ReturnType<ReturnType<typeof c4>>; | ||
export type c4oReturn = ReturnType<ReturnType<typeof cObj['c4']>>; | ||
export declare function d1(): () => (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
export declare function d2(): () => (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
export declare function d3(): () => (isNaN: number, bar: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
export declare function d4(): () => (isNaN: number) => typeof globalThis.isNaN; | ||
export type d4Return = ReturnType<ReturnType<ReturnType<ReturnType<typeof d4>>>>; | ||
export declare class A { | ||
method1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; | ||
method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN; | ||
method3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN; | ||
method4(isNaN: number): typeof globalThis.isNaN; | ||
} | ||
export declare function fromParameter(isNaN: number, bar: typeof globalThis.isNaN): () => { | ||
bar: typeof globalThis.isNaN; | ||
}; | ||
export declare const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; | ||
export declare function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN; | ||
export type AsObjectProperty = { | ||
isNaN: typeof globalThis.isNaN; | ||
}; | ||
export declare class AsClassProperty { | ||
isNaN?: typeof globalThis.isNaN; | ||
} | ||
export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN; |
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.
getExpandedParameters looks like it always returns an array of length 1, at least unless the rest type is somehow a 0-constituent union, but I think those are always impossible.
If the check is there just because the types could allow an empty array, maybe it should be an assert in the body of the
if
instead.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.
Check above, and you'll see:
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.
(Later I might see if we can avoid constructing a bunch of random arrays we don't need...)