Skip to content

Instantly share code, notes, and snippets.

@jjhoncv
Last active August 7, 2018 15:25
Show Gist options
  • Save jjhoncv/5e34c4e8225677febd430bb7685a9eed to your computer and use it in GitHub Desktop.
Save jjhoncv/5e34c4e8225677febd430bb7685a9eed to your computer and use it in GitHub Desktop.
typescript hacks

Tipos de casteo

propiedad readonly

hay 3 tipos de casteo

El primero con "<>"

interface letter {
 readonly text: string;
}var myletter = <letter>{
 text: 'aaa'
};myletter.text = 'dfsf';

El segundo con los ":"

interface letter {
  readonly  text: string;
}

var myletter: letter = {
  text: 'aaa'
};

myletter.text = 'dfsf';

El tercero con "as":

interface letter {
  readonly  text: string;
}

var myletter = {
  text: 'aaa'
} as letter

myletter.text = 'dfsf';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment