-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Use strict mode for internal TypeScript #504
Comments
Yep, I'm all for it. |
I think Deno should absolutely turn on strict mode for all end users if everyone involved in making Deno agrees that's the right thing to do. Personally I think it's the right thing to do - I usually turn on strictNullChecks on my code - I think we should do what's right rather than provide a bunch of configuration options. |
@benjamingr One of the nice things about dynamic languages is the ability to be messy and fast - I want to make sure that deno doesn't negate that feature. |
@ry can you give me an example where |
@benjamingr, I beg to differ. There are quite a few use cases that can easily frustrate people who are not familiar with TypeScript. I mentioned two above. Until things like this work out of the box, they will be surprising to users: declare const foo: Map<string, number>;
if (foo.has("bar")) {
const value: string = foo.get("bar"); // maybe undefined
}
declare bar: string | undefined;
assert(bar != null);
const value: string = bar; // might be undefined Both of those impact the internal code of demo, there maybe others. As long as there are valid, common patterns that require the not null assertion ( Personally I wouldn't be opposed to it being on by default, but I suspect I would lose that argument. It would be nice though if we only allow |
The part that's concerning me here is that I get the feeling like personally none of us seem to be too opposed to it being on by default (maybe Ryan is?) but we're all concerned about it. For what it's worth - I would personally be totally fine and unsurprised with the above - but that might be just personal bias being used to When was the last time you ran much code without strictNullChecks in production (or at all)? I totally get a REPL not running in strict mode though. |
We have a long time to make this decision before these semantics are locked down. Thanks for the input - I think we need to experiment with it. We’re not quite at the point where we can configure user tsconfig yet. |
I'm not sure is this a right place to speak about the user facing strictness, but my opinion is that:
Point being that if you use TS you probably love the types and the strictness, if you don't you use JS anyway. |
@Ciantic current thinking is that strict mode for TypeScript and type checking for JS will both be opt ins for end users via comfiguration. |
@ry has there been any decision about it one way or the other? It would be good to know the plan how to go about it before the 1.0 comes out. I would argue to use all of the flags posted by @kitsonk here as the default for all code, not only internal, and here is why: If the loose mode is the default when the API finalizes and people start writing code, it will never be possible to go more strict because it would break existing code. If the strict mode is the default and it turns out that it causes problems, it can be changed to loose mode without ever breaking any code so there is no risk in trying the strict default, but now is the only time when the strict default can be tried. If it means rewriting the code that is currently loose about null/undefined then I would like to help, as I would think that having the first runtime that doesn't suffer from The Billion Dollar Mistake would be well worth it. I would think about type safety in the same way as about security - I would prefer being safe by default and having to explicitly go unsafe than the other way around. And using TypeScript in a way that doesn't even make this type safe: const f = (x: string) => x.toLowerCase(); not to mention more complex examples, is not using TypeScript's full potential. In any case, whether you agree about the usefulness of avoiding That's why I hope that Deno 1.0 will use strict TypeScript by default. |
@rsp I think we should start another issue, which is setting |
Okay #3324 |
While it maybe too far of a journey at the moment to force strict mode on end users, it is likely a good idea to ensure that the internal Deno TypeScript is as strict as possible. Enabling
--strict
enables implicitly--noImplicitAny
,--noImplicitThis
,--alwaysStrict
,--strictNullChecks
,--strictFunctionTypes
and--strictPropertyInitialization
.The biggest "challenge" is that
null
andundefined
are incompatible with strict mode on, and the Deno TypeScript code is semi loose with this concept. The other challenge is a lot of code uses an assertion pattern for checking, instead of code branching. Currently TypeScript does not have a way of allowing this to affect call flow analysis (see: microsoft/TypeScript#8655) or co-dependent fields (see: microsoft/TypeScript#11117), which means that the not null assertion operator (!
) has to be used in some cases.The text was updated successfully, but these errors were encountered: