Search code examples
dartdart-editor

Is it possible to set the dart environment to enforce strict typing?


Is it possible to set the dart environment to enforce strict typing? If so how would i do that?


Solution

  • You can enable/disable checked mode.

    Checked mode is intended for development only.
    In production mode type annotation are ignored entirely.
    This is by philosophy and for performance reasons.
    Checked mode is not very strict though but this is all you can get currently.
    The only thing that helps is to add concrete type annotations instead of var.

    This topic was already discussed a lot.
    A few links I found:

    DartEditor launches in checked mode by default.
    When you use pub build the options --mode=debug or --mode=release specify if the output uses checked mode (debug) or not.

    When you launch a Dart script from command line you can add the -c option to enforce checked mode

    dart -c my_dart_script.dart