Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type annotations in lib.d.ts are not type safe #23353

Closed
andrewvarga opened this issue Apr 11, 2018 · 2 comments
Closed

Type annotations in lib.d.ts are not type safe #23353

andrewvarga opened this issue Apr 11, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@andrewvarga
Copy link

In lib.d.ts (TS 2.8.1) all the interfaces of WebGL objects like WebGLBuffer, WebGLTexture are empty, and so because of structural subtyping (duck typing), this code compiles without a problem:

let texture: WebGLTexture;
let buffer: WebGLBuffer = texture;

An external typing file I used for WebGL types solves this by adding dummyprops to these interfaces, which is a little hacky but works:
https://github.com/asgerf/dartify/blob/master/testcases/pixi/webgl.d.ts

I know this is intended behaviour for TypeScript but I was wondering if there is a better way to enforce type safety in situations like this?

@mhegazy
Copy link
Contributor

mhegazy commented Apr 11, 2018

i think this is the same as #5855

@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 11, 2018
@andrewvarga
Copy link
Author

Indeed.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants