tsconfig.json compiler options - Type Checking Flashcards

1
Q

What does allowUnreachableCode compiler option do?

A

When:

  • undefined - (default) provide suggestions as warnings to editors.
  • true - unreachable code is ignored.
  • false - raises compiler errors about unreachable code.
{
  "compilerOptions": {
    "allowUnreachableCode": true
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does allowUnusedLabels compiler option do?

A

When:

  • undefined (default) - provide suggestions as warnings to editors.
  • true - unused labels are ignored.
  • false - raises compiler errors about unused labels.
{
  "compilerOptions": {
    "allowUnusedLabels": true
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does alwaysStrict compiler option do?

A

Ensures that your files are parsed in the ECMAScript strict mode, and emit “use strict” for each source file.

{
  "compilerOptions": {
    "alwaysStrict": true
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does exactOptionalPropertyTypes compiler option do?

A

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
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does noFallthroughCasesInSwitch compiler option do?

A

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
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does noImplicitAny compiler option do?

A

TypeScript will issue an error whenever it infers any type.

{
	"compilerOptions": {
	  "noImplicitAny": true
	}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does noImplicitOverride compiler option do?

A

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
	}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does noImplicitReturns compiler option do?

A

When enabled, TypeScript will check all code paths in a function to ensure they return a value.

{
	"compilerOptions": {
	  "noImplicitReturns": true
	}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does noImplicitThis compiler option do?

A

TypeScript will issue an error on this expressions with an implied any type.

{
	"compilerOptions": {
	  "noImplicitThis": true
	}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does noPropertyAccessFromIndexSignature compiler option do?

A

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
	}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does noUncheckedIndexedAccess compiler option do?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does noUnusedLocals compiler option do?

A

Reports errors on unused local variables.

{
	"compilerOptions": {
	  "noUnusedLocals": true
	}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does noUnusedParameters compiler option do?

A

Reports errors on unused parameters in functions.

{
	"compilerOptions": {
	  "noUnusedLocals": true
	}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does strict compiler option do?

A

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
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does strictBindCallApply compiler option do?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does strictFunctionTypes compiler option do?

A

When enabled, this flag causes functions parameters to be checked more correctly.

{
  "compilerOptions": {
    "strictFunctionTypes": true
  }
}

Note: true if strict, false otherwise.

17
Q

What does strictNullChecks compiler option do?

A

When strictNullChecks is false, null and undefined are effectively ignored by the language. This can lead to unexpected errors at runtime.

When strictNullChecks is true, null and undefined have their own distinct types and you’ll get a type error if you try to use them where a concrete value is expected.

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Note: true if strict, false otherwise.

18
Q

What does strictPropertyInitialization compiler option do?

A

When set to true, TypeScript will raise an error when a class property was declared but not initialised in the constructor nor on declaration.

{
  "compilerOptions": {
    "strictPropertyInitialization": true
  }
}

Note: true if strict, false otherwise.

19
Q

What does useUnknownInCatchVariables compiler option do?

A

In TypeScript 4.0, support was added to allow changing the type of the variable in a catch clause from any to unknown.

This pattern ensures that error handling code becomes more comprehensive because you cannot guarantee that the object being thrown is a Error subclass ahead of time.

{
  "compilerOptions": {
    "useUnknownInCatchVariables": true
  }
}

Note: true if strict, false otherwise.