1. /*
    2. 属性接口: 对方法的参数的约束
    3. */
    4. interface Params{
    5. url: string,
    6. methods: string,
    7. data?:Object
    8. }
    9. function http(data: Params): void{
    10. console.log(data);
    11. }
    12. http({
    13. url: 'top250',
    14. methods: 'get'
    15. })
    16. http({
    17. url: 'login',
    18. methods: 'post',
    19. data: {
    20. username: 'lisi',
    21. pwd: 123
    22. }
    23. })