tsconfig.json compiler options - Type Checking Flashcards
What does allowUnreachableCode
compiler option do?
When:
-
undefined
- (default) provide suggestions as warnings to editors. -
true
- unreachable code is ignored. -
false
- raises compiler errors about unreachable code.
{ "compilerOptions": { "allowUnreachableCode": true } }
Source typescriptlang
What does allowUnusedLabels
compiler option do?
When:
-
undefined
(default) - provide suggestions as warnings to editors. -
true
- unused labels are ignored. -
false
- raises compiler errors about unused labels.
{ "compilerOptions": { "allowUnusedLabels": true } }
Source typescriptlang
What does alwaysStrict
compiler option do?
Ensures that your files are parsed in the ECMAScript strict mode, and emit “use strict”
for each source file.
{ "compilerOptions": { "alwaysStrict": true } }
Source typescriptlang
What does exactOptionalPropertyTypes
compiler option do?
exactOptionalPropertyTypes
makes TypeScript truly enforce the definition provided as an optional property.
It won’t allow undefined
as a valid value on optional interface properties.
{ "compilerOptions": { "exactOptionalPropertyTypes": true } }
Source typescriptlang
What does noFallthroughCasesInSwitch
compiler option do?
Report errors for fallthrough cases in switch statements. Ensures that any non-empty case inside a switch statement includes either break
or return
. This means you won’t accidentally ship a case fallthrough bug.
{ "compilerOptions": { "noFallthroughCasesInSwitch": true } }
Source typescriptlang
What does noImplicitAny
compiler option do?
TypeScript will issue an error whenever it infers any
type.
{ "compilerOptions": { "noImplicitAny": true } }
Source typescriptlang
What does noImplicitOverride
compiler option do?
Using noImplicitOverride
you can ensure that the sub-classes never go out of sync, by ensuring that functions which override include the keyword override
.
{ "compilerOptions": { "noImplicitOverride": true } }
Source typescriptlang
What does noImplicitReturns
compiler option do?
When enabled, TypeScript will check all code paths in a function to ensure they return a value.
{ "compilerOptions": { "noImplicitReturns": true } }
Source typescriptlang
What does noImplicitThis
compiler option do?
TypeScript will issue an error on this
expressions with an implied any
type.
{ "compilerOptions": { "noImplicitThis": true } }
Source typescriptlang
What does noPropertyAccessFromIndexSignature
compiler option do?
This setting ensures consistency between accessing a field via the “dot” (obj.key
) syntax, and “indexed” (obj["key"]
) and the way which the property is declared in the type.
Without this flag, TypeScript will allow you to use the dot syntax to access fields which are not defined.
{ "compilerOptions": { "noPropertyAccessFromIndexSignature": true } }
Source typescriptlang
What does noUncheckedIndexedAccess
compiler option do?
TypeScript has a way to describe objects which have unknown keys but known values on an object, via index signatures.
interface EnvironmentVars { NAME: string; OS: string; // Unknown properties are covered by this index signature. [propName: string]: string; } declare const env: EnvironmentVars; const nodeEnv = env.NODE_ENV;// type is string
Turning on noUncheckedIndexedAccess
will add undefined
to any un-declared field in the type.
declare const env: EnvironmentVars; const nodeEnv = env.NODE_ENV;// type is string | undefined
Source typescriptlang
What does noUnusedLocals
compiler option do?
Reports errors on unused local variables.
{ "compilerOptions": { "noUnusedLocals": true } }
Source typescriptlang
What does noUnusedParameters
compiler option do?
Reports errors on unused parameters in functions.
{ "compilerOptions": { "noUnusedLocals": true } }
Source typescriptlang
What does strict
compiler option do?
The strict
flag enables a wide range of type checking behavior that results in stronger guarantees of program correctness. Turning this on is equivalent to enabling all of the strict mode family options. You can then turn off individual strict mode family checks as needed.
{ "compilerOptions": { "strict": true } }
Source typescriptlang
What does strictBindCallApply
compiler option do?
When set, TypeScript will check that the built-in methods of functions call
, bind
, and apply
are invoked with correct argument for the underlying function.
{ "compilerOptions": { "strictBindCallApply": true } }
Note: true
if strict
, false
otherwise.
Source typescriptlang