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

Example doesn't work #1263

Open
sv158 opened this issue Dec 3, 2019 · 2 comments
Open

Example doesn't work #1263

sv158 opened this issue Dec 3, 2019 · 2 comments

Comments

@sv158
Copy link

sv158 commented Dec 3, 2019

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.

@orta
Copy link
Contributor

orta commented Dec 3, 2019

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

@sv158
Copy link
Author

sv158 commented Dec 4, 2019

@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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants