-
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
Uncalled function checks check negation condition #57114
Changes from 5 commits
09cced4
00cc8ff
3793795
bdb2698
a9abcb4
4bac889
a5d6425
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,9 +131,6 @@ let pollingChunkSize = createPollingIntervalBasedLevels(defaultChunkLevels); | |
export let unchangedPollThresholds = createPollingIntervalBasedLevels(defaultChunkLevels); | ||
|
||
function setCustomPollingValues(system: System) { | ||
if (!system.getEnvironmentVariable) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used VSCode to search for all implementations of
so I felt safe removing this check -- the condition cannot currently evaluate to true. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are theoretically external implementations of sys out there, and I'm guessing this guards against them. https://github.com/ionic-team/stencil/blob/fa5ab1b75f19e1117f0cead1caaf6b00ddccadf3/src/compiler/sys/typescript/typescript-sys.ts#L182 (but this code is non-functional post 5.0) |
||
return; | ||
} | ||
const pollingIntervalChanged = setCustomLevels("TSC_WATCH_POLLINGINTERVAL", PollingInterval); | ||
pollingChunkSize = getCustomPollingBasedLevels("TSC_WATCH_POLLINGCHUNKSIZE", defaultChunkLevels) || pollingChunkSize; | ||
unchangedPollThresholds = getCustomPollingBasedLevels("TSC_WATCH_UNCHANGEDPOLLTHRESHOLDS", defaultChunkLevels) || unchangedPollThresholds; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1182,8 +1182,6 @@ function getCompletionEntriesFromTypings(host: LanguageServiceHost, options: Com | |
} | ||
|
||
function enumerateNodeModulesVisibleToScript(host: LanguageServiceHost, scriptPath: string): readonly string[] { | ||
if (!host.readFile || !host.fileExists) return emptyArray; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The LanguageServiceHost has a comment
so I believe these checks have been unnecessary since the compiler was converted to modules in #51387 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would git blame this; node16 is a "recent" addition and requiring those would be new, so this is likely a compatibility shim to ensure that older callers don't crash. We do this sort of thing somewhat often when making "breaking" API changes (but, still detecting older uses and trying to fix them within reason). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like it went in 6 years ago with 70682b7#diff-10538e33f93edc9b510a4cd505ecaa718f6ab878a54b7d044a18ef10b1e36792R383 . Better understanding the compatibility shim, I'll undo the changes that assume |
||
|
||
const result: string[] = []; | ||
for (const packageJson of findPackageJsons(scriptPath, host)) { | ||
const contents = readJson(packageJson, host as { readFile: (filename: string) => string | undefined; }); // Cast to assert that readFile is defined | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
three.ts(28,14): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
|
||
|
||
==== one.ts (0 errors) ==== | ||
declare const y: never[] | string[]; | ||
export const yThen = y.map(item => item.length); | ||
==== two.ts (0 errors) ==== | ||
declare const y: number[][] | string[]; | ||
export const yThen = y.map(item => item.length); | ||
==== three.ts (1 errors) ==== | ||
// #42504 | ||
interface ResizeObserverCallback { | ||
(entries: ResizeObserverEntry[], observer: ResizeObserver): void; | ||
} | ||
interface ResizeObserverCallback { // duplicate for effect | ||
(entries: ResizeObserverEntry[], observer: ResizeObserver): void; | ||
} | ||
|
||
const resizeObserver = new ResizeObserver(([entry]) => { | ||
entry | ||
}); | ||
// comment in #35501 | ||
interface Callback<T> { | ||
(error: null, result: T): unknown | ||
(error: Error, result: null): unknown | ||
} | ||
|
||
interface Task<T> { | ||
(callback: Callback<T>): unknown | ||
} | ||
|
||
export function series<T>(tasks: Task<T>[], callback: Callback<T[]>): void { | ||
let index = 0 | ||
let results: T[] = [] | ||
|
||
function next() { | ||
let task = tasks[index] | ||
if (!task) { | ||
~~~~ | ||
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? | ||
callback(null, results) | ||
} else { | ||
task((error, result) => { | ||
if (error) { | ||
callback(error, null) | ||
} else { | ||
// must use postfix-!, since `error` and `result` don't have a | ||
// causal relationship when the overloads are combined | ||
results.push(result!) | ||
next() | ||
} | ||
}) | ||
} | ||
} | ||
next() | ||
} | ||
|
||
series([ | ||
cb => setTimeout(() => cb(null, 1), 300), | ||
cb => setTimeout(() => cb(null, 2), 200), | ||
cb => setTimeout(() => cb(null, 3), 100), | ||
], (error, results) => { | ||
if (error) { | ||
console.error(error) | ||
} else { | ||
console.log(results) | ||
} | ||
}) | ||
|
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.
On the
ModuleSpecifierResolutionHost
,host.fileExists
is always defined, buthost.readFile
is optionally defined.Searching the codebase for
host.fileExists
showed it being used multiple times without a check, so I felt safe removing this. If you think this is wrong or risky, I'm happy to replace this withor however you think the codebase is best maintained.
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.
This one I believe is correct; this same change was made in #53463.