Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Example doesn't work  #1263

Open
Open

Description

@sv158

https://github.com/microsoft/TypeScript-Handbook/blame/master/pages/Advanced%20Types.md#L500

type LinkedList<T> = T & { next: LinkedList<T> };

interface Person {
    name: string;
}

var people: LinkedList<Person>;
var s = people.name;  
var s = people.next.name;
var s = people.next.next.name;
var s = people.next.next.next.name;

Variable 'people' is used before being assigned.

Activity

  1. orta commented on Dec 3, 2019

    @orta
    Contributor

    Looks legit, want to submit a PR making that declare var people?

  2. sv158 commented on Dec 4, 2019

    @sv158
    Author

    Orta Therox (@orta) while using declare var, the js code generated is different.

    There is also a similar problem at https://github.com/microsoft/TypeScript-Handbook/blame/master/pages/Type%20Compatibility.md#L221

    interface Empty<T> {
    }
    let x: Empty<number>;
    let y: Empty<string>;
    x = y;  // variable 'y' is used before being assigned.

    and https://github.com/microsoft/TypeScript-Handbook/blame/master/pages/Type%20Compatibility.md#L200

    class Animal {
        feet: number;
        constructor(name: string, numFeet: number) { }
    }
    class Size {
        feet: number;
        constructor(numFeet: number) { }
    }
    let a: Animal;
    let s: Size;
    a = s;  // variable 's' is used before being assigned.
    s = a;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions