TypeScript: checking at compile time if an Array lists all property keys

The problem  #
Consider the following TypeScript code:
interface Person {
first: string;
last: string;
}

const personKeys = [
‘first’,
‘last’,
] as const;

personKeys lists the property keys of Person. Can we check at compile time if this list…


This content originally appeared on 2ality – JavaScript and more and was authored by Dr. Axel Rauschmayer

The problem  

Consider the following TypeScript code:

interface Person {
  first: string;
  last: string;
}

const personKeys = [
  'first',
  'last',
] as const;

personKeys lists the property keys of Person. Can we check at compile time if this list is correct?

[Read rest of post]


This content originally appeared on 2ality – JavaScript and more and was authored by Dr. Axel Rauschmayer


Print Share Comment Cite Upload Translate Updates
APA

Dr. Axel Rauschmayer | Sciencx (2022-07-27T00:00:00+00:00) TypeScript: checking at compile time if an Array lists all property keys. Retrieved from https://www.scien.cx/2022/07/27/typescript-checking-at-compile-time-if-an-array-lists-all-property-keys/

MLA
" » TypeScript: checking at compile time if an Array lists all property keys." Dr. Axel Rauschmayer | Sciencx - Wednesday July 27, 2022, https://www.scien.cx/2022/07/27/typescript-checking-at-compile-time-if-an-array-lists-all-property-keys/
HARVARD
Dr. Axel Rauschmayer | Sciencx Wednesday July 27, 2022 » TypeScript: checking at compile time if an Array lists all property keys., viewed ,<https://www.scien.cx/2022/07/27/typescript-checking-at-compile-time-if-an-array-lists-all-property-keys/>
VANCOUVER
Dr. Axel Rauschmayer | Sciencx - » TypeScript: checking at compile time if an Array lists all property keys. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/27/typescript-checking-at-compile-time-if-an-array-lists-all-property-keys/
CHICAGO
" » TypeScript: checking at compile time if an Array lists all property keys." Dr. Axel Rauschmayer | Sciencx - Accessed . https://www.scien.cx/2022/07/27/typescript-checking-at-compile-time-if-an-array-lists-all-property-keys/
IEEE
" » TypeScript: checking at compile time if an Array lists all property keys." Dr. Axel Rauschmayer | Sciencx [Online]. Available: https://www.scien.cx/2022/07/27/typescript-checking-at-compile-time-if-an-array-lists-all-property-keys/. [Accessed: ]
rf:citation
» TypeScript: checking at compile time if an Array lists all property keys | Dr. Axel Rauschmayer | Sciencx | https://www.scien.cx/2022/07/27/typescript-checking-at-compile-time-if-an-array-lists-all-property-keys/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.