You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In 5.5, we started checking to ensure that signatures withoutthis type predicates are not assignable to signatures with this type predicates..
We thought the fact that we didn't do this check was an oversight, but...maybe not?
exportinterfaceFoo{isBlah(): this is {blah: true};}letobj: Foo={isBlah(): this is {blah: true}{// ~~~~// Error! A 'this' type is available only in a non-static member of a class or interface.returntrue;}}
You can't refer to the this type in an object literal.
So...it's impossible to implement an object with this signature.
But wait... in that position, this is not a type, it's a value.
And things work correctly on use-site.
So this is probably just a bug on where we try to check if this is used correctly.
Also what happens if you write...
letisBlah=obj.isBlah;if(isBlah()){// ...// Should `window.blah` exist? 😄}
If you write import 'foo', and foo doesn't exist, TypeScript doesn't error.
Typically people do this to bring .css files into an environment.
So for those people, it's a "feature".
This flag (resolveSideEffectImports) tries to at least resolve the path and bring it into the program.
We don't read arbitrary files into the program though.
Code change is pretty small.
Most of the test failures are CSS imports.
On DefinitelyTyped, it's people reading .css files.
Why not just resolve but not bring it into the program? Because the way things work now, it will error on .css files unless you have declare module "*.css".
We'd need to start creating file-watchers for non-existent paths?
Why don't we always turn this on? Seems crazy that we don't error when you write a path.
Mainly backwards-compatibility.
This all probably predates wildcard modules.
So this always brings the JS/TS file into the program. What happens when you import a JS file without a .d.ts file?
(without allowJs)
Should we make that an implicitAny error?
Probably shouldn't be an error, right?
Well... yes, seems like we are strict here, but the file should just add an export {}.
We like it in general.
Should it be resolve or check?
So checkSideEffectImports?
checkSideEffectImportSpecifiers - Specifiers because we already check if it resolves, but we don't check that the specifier is valid.
The text was updated successfully, but these errors were encountered:
checkSideEffectImportSpecifiers - Specifiers because we already check if it resolves, but we don't check that the specifier is valid.
I'm struggling to parse this - what's the difference between checking if it resolves and checking that it's valid? If TypeScript already checks whether a given specifier resolves, I would expect that to mean it errors if the corresponding file doesn't exist.
what's the difference between checking if it resolves and checking that it's valid? If TypeScript already checks whether a given specifier resolves, I would expect that to mean it errors if the corresponding file doesn't exist.
Checking to see if it resolve is what the new flag would do. Today, you can write:
import"hello-world-this-is-fake";
And it won't error at all. If it does exist, we technically will resolve it, sort of, to pull its referenced files in, but we won't resolve it enough to actually issue an error or anything. So it's down to "semantics" on what the name should be.
No Suspect Truthy Checks
#59217
if (/some regex/)
accidentally - but so many expressions are always truthy.x === { prop: obj }
because it's always false.if ([some, array, contents])
and similar things.foo > bar ?? baz
where the user assumed it was equivalent tofoo > (bar ?? baz)
.no-constant-binary-expression
is the closest ESLint rule we're aware of, but it doesn't do all of this.#57103
In 5.5, we started checking to ensure that signatures without
this
type predicates are not assignable to signatures withthis
type predicates..We thought the fact that we didn't do this check was an oversight, but...maybe not?
You can't refer to the
this
type in an object literal.So...it's impossible to implement an object with this signature.
But wait... in that position,
this
is not a type, it's a value.this
is used correctly.Also what happens if you write...
Flag for Side-Effect Imports
#58941
import 'foo'
, andfoo
doesn't exist, TypeScript doesn't error..css
files into an environment.resolveSideEffectImports
) tries to at least resolve the path and bring it into the program..css
files..css
files unless you havedeclare module "*.css"
..d.ts
file?allowJs
)implicitAny
error?export {}
.resolve
orcheck
?checkSideEffectImports
?checkSideEffectImportSpecifiers
-Specifiers
because we already check if it resolves, but we don't check that the specifier is valid.The text was updated successfully, but these errors were encountered: