type Message = {
  id: number;
  body: string;
}

type State = {
  messages: Message[]
}

const messages: Message[] = [
  {
    id: 1,
    body: 'Hi!',
    createdAt: '2019-07-16T07:21:40.878Z' // this will throw an error as I would expect as the `createdAt` is not defined in the `Message` type
  },
  {
    id: 2,
    body: 'Hey! 💪🏻🤩'
  }
]


class MyComponent extends React.Component<{}, State> {
  constructor(props) {
    super(props);
  
    this.state = {
      messages
    }
  }
  
  addMessage = (text: string) => {
    this.setState(state => ({
      messages: [
        ...state.messages,
        {
          id: 20,
          body: text,
          createdAt: '' // I would expect the same error being thrown here, why there is no error?? and why the `messages` (line 34) type gets extended with the object literal that icludes `createdAt`
        }
      ]
    }))
  }
  
  render() {
    return null
  }  
}